Prerequisites
Before creating a new sudo user, make sure you have:
- SSH access to your VPS as root (username:
hxroot) - Your server IP address
- Root password
Why Create a Sudo User?
Using the root account for daily tasks is a security risk. A sudo user can:
- Run administrative commands only when needed
- Have their own password and SSH key
- Provide an audit trail of commands
- Reduce the risk of accidental system damage
Step 1: Connect to Your VPS as Root
Open your terminal (Mac/Linux) or PuTTY (Windows) and connect:
ssh hxroot@YOUR_SERVER_IP -p 22Enter your root password when prompted.
Step 2: Create a New User
Replace username with your desired username:
adduser usernameYou will be prompted to:
- Enter and confirm a password for the new user
- Enter user information (optional - you can press Enter to skip)
Adding user `john' ...
Adding new group `john' (1001) ...
Adding new user `john' (1001) with group `john' ...
Creating home directory `/home/john' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfullyStep 3: Add User to Sudo Group (Ubuntu/Debian)
Give the user administrative privileges:
usermod -aG sudo usernameStep 3 Alternative: For CentOS/Rocky/AlmaLinux
On RHEL-based systems, use the wheel group:
usermod -aG wheel usernameStep 4: Verify Sudo Access
Switch to the new user and test sudo:
su - usernamesudo whoamiYou should see:
rootStep 5 (Optional): Set Up SSH Key for New User
For passwordless login (more secure):
On your local machine, copy your SSH key:
ssh-copy-id username@YOUR_SERVER_IPStep 6 (Optional): Disable Root Login (Advanced Security)
After confirming your sudo user works, you can disable root SSH access:
sudo nano /etc/ssh/sshd_configFind and change:
PermitRootLogin noThen restart SSH:
sudo systemctl restart sshd⚠️ Warning: Only disable root login after you have confirmed your sudo user can run commands with sudo.
Common Sudo Commands
sudo apt update- Update package listssudo systemctl restart nginx- Restart a servicesudo nano /etc/hosts- Edit system filessudo ufw enable- Enable firewall