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

本站现有博文328篇,共被浏览856700

本站已经建立2564天!

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