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

本站现有博文340篇,共被浏览1007123次

本站已经建立2715天!

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