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

本站现有博文327篇,共被浏览833135

本站已经建立2538天!

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