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

本站现有博文336篇,共被浏览943330

本站已经建立2653天!

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