SSH keys and root access
This guide covers how SSH keys are safer than passwords, how to create and add a key, and how root and sudo access work. You will also learn some basic Linux navigation.
Before you begin
- SSH access to your VPS. See Access details and SSH.
- A computer where you can create a key pair.
- Confirmation that your plan gives you root access. Some plans may limit it.
Keep private keys private
A private key is a secret. Never share it, email it, or store it in a public place. Only the public key goes on the server.
Steps
Create a key pair (on your own computer)
On your own computer, choose an unused key filename. Never overwrite an existing private key when prompted:
bashssh-keygen -t ed25519 -C "your-label"Set a passphrase when asked. It protects the key if someone gets the file.
Add the public key to the server
- Copy the contents of the public key file, which ends in
.pub. - Add it to the server's authorised keys for your user, using the method your VPS documentation shows.
- Test the key in a new terminal before you close your current session.
Root and sudo
- Use your normal user for daily work, and use
sudoonly for the commands that need it. - Avoid logging in directly as root for everyday tasks.
- Check what you are about to run before you add
sudoto it.
Basic Linux navigation
pwdshows where you are.ls -lalists files.cd foldermoves into a folder.cat fileprints a file.nano fileopens a simple editor.df -hshows disk space.free -hshows memory.
Expected result
You can sign in with your key, and sudo works for the commands you need.
If something goes wrong
- The key is refused. Check that you copied the public key, not the private key, and that the file permissions are correct.
- Locked out after a change. Keep your current session open while you test a new key. If you are locked out, contact support.
- Sudo asks for a password you do not know. Your user may not have sudo access. Check your plan or ask support.
Related articles
Last reviewed
2026-10-28
