EADST

Adding a User in Linux with Password and Sudo Privileges

Managing users in a Linux environment is a crucial task for system administrators. This guide covers the steps to create a new user, set a password, and grant them sudo privileges.

1. Creating a New User

To create a new user, use the adduser command. This command automatically creates a home directory and sets up the environment.

sudo adduser username

Replace username with the desired username. The system will prompt you to set a password and provide other optional details.

2. Setting the User's Password

During the user creation process, you will be asked to set a password. However, if you want to change the password later, use the passwd command:

sudo passwd username

Enter the new password when prompted. Ensure it's strong and secure.

3. Granting Sudo Privileges

To grant the new user sudo privileges, you need to edit the sudoers file. This file controls the sudo access for users and groups. It's crucial to use the visudo command to safely edit this file, as it checks for syntax errors before saving.

Method 1: Using visudo

Open the sudoers file with visudo:

sudo visudo

Add the User to the sudoers File:

In the sudoers file, add a line for the new user:

username ALL=(ALL:ALL) ALL

Replace username with the actual username. This grants the user full sudo privileges.

Save and Exit:

In Vim, save the file and exit by pressing Esc, typing :wq, and pressing Enter.

Method 2: Directly Editing /etc/sudoers

Open the sudoers file:

sudo vim /etc/sudoers

Edit Carefully:

Add the following line, ensuring no syntax errors:

username ALL=(ALL:ALL) ALL

Save and Exit:

Again, save and exit by pressing Esc, typing :wq, and pressing Enter.

4. Verifying Sudo Access

To confirm that the user has sudo privileges, switch to the new user and run a command with sudo. For example:

su - username
sudo whoami

The command should return root, indicating that the user has sudo access.

Conclusion

Adding a user with sudo privileges in Linux involves creating the user, setting a password, and modifying the sudoers file. Always edit the sudoers file carefully to avoid syntax errors that could disrupt system access. Grant sudo access judiciously to maintain system security.

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
LeetCode QWEN mmap CAM GPT4 FP16 腾讯云 Knowledge 财报 多线程 EXCEL VGG-16 Review Docker Domain API GIT Vmess Web Interview Pandas Google CV Augmentation tar 飞书 Hungarian CLAP Random OpenCV Pillow Linux 继承 SVR Ubuntu Logo Magnet ResNet-50 FP64 WebCrawler 图形思考法 Safetensors Paper Statistics NameSilo LLAMA Food Datetime printf ONNX CEIR Search Bert Tiktoken TensorRT CSV Algorithm 版权 Hotel 第一性原理 Michelin Land Gemma logger 递归学习法 FlashAttention LLM Breakpoint 签证 Attention Django Card Llama git-lfs News DeepSeek Clash 净利润 Heatmap XGBoost Data NLTK Pickle AI HaggingFace Firewall MD5 CC SPIE Dataset 证件照 DeepStream Translation FP32 Streamlit RAR Password 音频 Github UI transformers Input Use BTC Freesound Cloudreve SAM HuggingFace VPN v0.dev Template torchinfo InvalidArgumentError Quantize Math Markdown SQL tqdm Numpy IndexTTS2 Pytorch Color YOLO Baidu LoRA ChatGPT Distillation llama.cpp CTC GoogLeNet Transformers 顶会 TSV Jetson CUDA Quantization SQLite RGB Agent Tracking 关于博主 BF16 Plate Excel Bitcoin XML NLP GGML Ptyhon ModelScope Base64 多进程 搞笑 公式 Anaconda WAN Conda Git Vim Animate Diagram diffusers Bipartite LaTeX Nginx PyCharm 阿里云 Tensor FastAPI PIP Mixtral UNIX Plotly TTS FP8 Zip Video 报税 PDB Proxy git GPTQ PyTorch Python Qwen2 uwsgi v2ray Disk Jupyter Sklearn VSCode Shortcut Hilton Image2Text Miniforge Qwen Bin Paddle hf Windows COCO JSON Crawler scipy Claude BeautifulSoup PDF 强化学习 Website TensorFlow OpenAI 算法题 Qwen2.5 Permission 域名 OCR C++ uWSGI
站点统计

本站现有博文320篇,共被浏览756514

本站已经建立2420天!

热门文章
文章归档
回到顶部