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

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

本站已经建立2474天!

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