How to create a user with sudo privileges
Updated 11/29/2026
Working as root all the time is risky: one mistake can destroy the server. A normal user with sudo asks for your password to confirm administrative commands.
1. Create the user
adduser andrew
Set a password and fill in the requested details.
2. Grant sudo privileges
usermod -aG sudo andrew
3. Test
Log in as the new user and run a command with sudo:
su - andrew
sudo apt-get update
4. Copy your SSH keys (recommended)
So you can connect directly as the new user with keys:
mkdir -p /home/andrew/.ssh
cp ~/.ssh/authorized_keys /home/andrew/.ssh/
chown -R andrew:andrew /home/andrew/.ssh
chmod 700 /home/andrew/.ssh
Now you can safely disable root login.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Single sign-on for your applications with authentik
One account for all your team's apps: first sign-in, users, an OpenID Connect application and two-factor authentication.
Updated 11/29/2026SecurityPasswordless sign-in with Pocket ID
Passkeys for your applications over OpenID Connect: first sign-in, colleagues and connecting an application.
Updated 11/29/2026SecurityHow to protect your server from brute-force attacks with fail2ban
fail2ban automatically bans IPs that repeatedly try wrong passwords. Here is how to install and configure it.
Updated 11/29/2026