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

本站现有博文339篇,共被浏览998529次

本站已经建立2709天!

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