How to Create a New Sudo User on Linux
Creating a new user with sudo privileges is a best practice for managing Linux servers securely without using the root account.
1. Create the User
Replace username
with your desired name:
sudo adduser username
You’ll be prompted to set a password and (optionally) fill in user details.
2. Add the User to the Sudo Group
For Ubuntu/Debian:
sudo usermod -aG sudo username
For CentOS/RHEL:
sudo usermod -aG wheel username
3. Switch to the New User
su - username
4. Test Sudo Access
sudo whoami
It should return root
if everything is set up correctly.
5. Optional: Disable Root Login (Advanced)
For added security, disable direct root login:
sudo nano /etc/ssh/sshd_config
Set the following line:
PermitRootLogin no
Then restart SSH:
sudo systemctl restart sshd
Summary
Using sudo users instead of logging in as root improves server security and minimizes risk. This method is standard for secure and efficient server management.