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

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

本站已经建立2719天!

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