How to create non-root user on Hostinger
Log in as root via Hostinger hPanel Terminal or SSH, create a new user with <code>adduser username</code>, add to sudo group using <code>usermod -aG sudo username</code>, test with <code>su - username</code> and <code>sudo whoami</code>. This enhances security by avoiding daily root logins. Optionally set up SSH keys and disable root login.
Prerequisites
- Hostinger VPS with Ubuntu/Debian
- Root access via hPanel Terminal or SSH
- Basic terminal knowledge
- VPS IP address and root password
Step-by-Step Instructions
Access VPS Terminal as root
ssh root@<VPS_IP> and enter root password if prompted.Verify root login
whoami to confirm output shows root. The prompt should end with # instead of $, indicating root privileges.Create new non-root user
adduser <username> (e.g., adduser myuser). Enter a strong password twice when prompted, fill optional GECOS fields like full name or press Enter to skip, then type Y and Enter to confirm. The user's home directory will be /home/<username> with shell /bin/bash.Add user to sudo group
usermod -aG sudo <username> (e.g., usermod -aG sudo myuser). This grants the user administrative privileges via sudo commands without needing root login.Test the new user locally
su - <username>, enter the user's password. Prompt changes to $. Run whoami to verify username, then sudo whoami (enter user password; should output root).Exit test and enable SSH for non-root
exit to return to root. Test SSH login from local machine: ssh <username>@<VPS_IP> and enter user password. For better security, generate SSH keys locally with ssh-keygen and copy public key using ssh-copy-id root@<VPS_IP>.Update packages as non-root user
sudo apt update && sudo apt upgrade -y. Enter user password when prompted. This demonstrates sudo functionality for maintenance tasks.Enhance security by disabling root login
sudo nano /etc/ssh/sshd_config, set PermitRootLogin no, save and exit, then restart SSH: sudo systemctl restart ssh. Now only non-root SSH is allowed.Common Issues & Troubleshooting
useradd: user <username> already exists
Choose a different username and retry <code>adduser <newusername></code>.
User is not in the sudoers file. This incident will be reported.
Run <code>usermod -aG sudo <username></code> as root and log out/in to apply group changes.
Cannot SSH as non-root user
Ensure <code>PasswordAuthentication yes</code> in <code>/etc/ssh/sshd_config</code>, restart SSH, or set up SSH keys.
sudo prompts for root password instead of user password
Switch to user with <code>su - <username></code> or log out/in; sudo uses user password by default.
Weak password rejected
Use a strong password with uppercase, lowercase, numbers, and symbols to meet Linux policy.