Users and sudo instead of root
How to create a working user, give them sudo, move SSH keys, and stop logging in to the server as root.
Updated August 23, 2026
The machine comes with full root access, and your first instinct is to keep working as root. That's convenient right up until the first typo in rm -rf. The working setup is different: a regular user for everyday tasks, root through sudo and only when you actually need it.
Create a user
Debian and Ubuntu:
adduser artem
usermod -aG sudo artem
AlmaLinux and CentOS Stream:
adduser artem
passwd artem
usermod -aG wheel artem
The group differs: sudo on the Debian family, wheel on the RHEL family. Check the rights:
sudo -l -U artem
Move the SSH keys
Keys added in the "Access" tab of the panel /hosting/vds/m/<id> land with the root user. You have to place them for the new user yourself:
mkdir -p /home/artem/.ssh
cp /root/.ssh/authorized_keys /home/artem/.ssh/
chown -R artem:artem /home/artem/.ssh
chmod 700 /home/artem/.ssh
chmod 600 /home/artem/.ssh/authorized_keys
Permissions here are not a formality: if they are too loose, sshd will silently refuse to accept the key.
Check that you can log in as the new user in a separate terminal window without closing the current one:
ssh artem@<address>
sudo whoami
Only after a successful check should you move on to disabling root login.
How to use sudo
sudo systemctl restart nginx
sudo -i
sudo -u www-data ls /var/www
sudo -i gives you a full root shell — for a series of commands, not for permanent work. Every call to sudo is written to the log, and that is your trail when investigating an incident:
journalctl -t sudo -n 50
grep sudo /var/log/auth.log
More about logs — who logged in to the machine.
Rights for services
Another common mistake is running an application as root "so it works". For each service, create a system user without a shell:
useradd --system --no-create-home --shell /usr/sbin/nologin appsrv
chown -R appsrv:appsrv /opt/app
Then a hole in the application doesn't hand the attacker the whole machine at once.
Common mistakes
| Mistake | Cause | Solution |
|---|---|---|
artem is not in the sudoers file | Not in the group or didn't log in again | usermod -aG sudo artem, log in again |
| Key is not accepted | Permissions on .ssh are wider than 700 or the owner is root | chown and chmod as above |
| sudo password doesn't work | The user has no password set | passwd artem |
| Editing sudoers broke sudo | A syntax error in the file | Only visudo; repair via rescue mode |
Edit
/etc/sudoersexclusively with thevisudocommand — it checks the syntax before saving. A broken file takes sudo away from everyone at once.