How to Create a New User with Sudo Access on Your VPS
Creating a separate user with sudo privileges is one of the first security steps you should take after deploying a Linux VPS. Instead of using the root account for everyday administration, a sudo-enabled user provides better security, accountability, and reduces the risk of accidental system changes.
Why Use a Sudo User?
- Improves VPS security
- Reduces the risk of accidental system damage
- Follows Linux security best practices
- Recommended for Ubuntu, Debian, CentOS, AlmaLinux and Rocky Linux servers
Requirements
- Root SSH access
- A Linux VPS (Ubuntu, Debian, CentOS, AlmaLinux or Rocky Linux)
- SSH client such as PuTTY or Terminal
Step 1 — Connect to Your VPS
Login to your server as the root user.
ssh root@YOUR_SERVER_IP
Replace YOUR_SERVER_IP with your actual VPS IP address.
Step 2 — Create a New User
Create a new Linux user. Replace newuser with your preferred username.
adduser newuser
or on some Linux distributions:
useradd -m newuser
The system will ask you to create a secure password.
Step 3 — Grant Sudo Privileges
Ubuntu / Debian
usermod -aG sudo newuser
CentOS / AlmaLinux / Rocky Linux
usermod -aG wheel newuser
Step 4 — Verify Group Membership
groups newuser
Example output:
newuser : newuser sudo
Step 5 — Test Sudo Access
Switch to the new account.
su - newuser
Then run:
sudo whoami
If everything is configured correctly, the output should be:
root
This confirms that the new user has administrative privileges.
Security Best Practices
- Use your sudo user instead of the root account for daily administration.
- Disable direct root SSH login after confirming sudo access.
- Enable a firewall such as UFW or Firewalld.
- Install Fail2Ban to protect against brute-force attacks.
- Keep your VPS updated with the latest security patches.
- Consider using SSH keys instead of passwords.
Common Issues
User is not in the sudoers file
Run the following command and then log out and log back in.
usermod -aG sudo newuser
Sudo command not found
Install sudo:
Ubuntu / Debian
apt install sudo
CentOS / AlmaLinux
dnf install sudo
Conclusion
Creating a dedicated user with sudo privileges is a simple but essential step toward securing your Linux VPS. It minimizes security risks, follows industry best practices, and makes server administration safer for production environments.
Related Guides
- How to Connect to Your VPS via SSH
- Why You Should Disable Root Login on Your VPS
- How to Change Your SSH Port
- Best Practices to Secure Your VPS
- VPS Security Checklist for Beginners
