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

本站现有博文333篇,共被浏览913730

本站已经建立2616天!

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