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

本站现有博文321篇,共被浏览775122

本站已经建立2465天!

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