Skip to content
VDS · Operating systems

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

MistakeCauseSolution
artem is not in the sudoers fileNot in the group or didn't log in againusermod -aG sudo artem, log in again
Key is not acceptedPermissions on .ssh are wider than 700 or the owner is rootchown and chmod as above
sudo password doesn't workThe user has no password setpasswd artem
Editing sudoers broke sudoA syntax error in the fileOnly visudo; repair via rescue mode

Edit /etc/sudoers exclusively with the visudo command — it checks the syntax before saving. A broken file takes sudo away from everyone at once.