How to create a user with sudo privileges
Updated 7/20/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
How to scan your server for malware with ClamAV
Install ClamAV, an open-source antivirus, and periodically scan your server for infected files.
Updated 7/20/2026SecurityHow to check which ports are open on your server
Find out which services are listening for connections on your server and close what you do not need, for less exposure.
Updated 7/20/2026SecurityHow to add security headers to your website
A few HTTP headers protect your visitors from common attacks like clickjacking and content injection.
Updated 7/20/2026