
Initial Setup for a VPS
Create a new user
First up, create a new user and add them to the sudo group. Never login as the root user!
Here’s the command to create a new user:
adduser {name}
And here’s how we add them to the sudo group:
usermod -aG sudo {name}
Login with SSH Key
Next, we’ll generate an SSH key (or use an existing one) and add it to the authorised keys file on the VPS.
The key must be generated on your local machine, not the VPS.
Generate the key locally:
ssh-keygen -t ed25519
Copy the public key to your clipboard:
pbcopy < ~/.ssh/id_ed25519.pub
SSH into your VPS and create the .ssh directory in your home directory if it doesn’t already exist:
mkdir ~/.ssh
Create a file in the ~/.ssh directory called authorized_keys and paste your key into it:
touch ~/.ssh/authorized_keys
pbpaste > ~/.ssh/authorized_keys
You should now be able to exit the SSH session to your VPS and re-login with the SSH key without providing a password. Fun times.
Disable Password Login
Troubleshooting
If you’re still able to login with a password you can grep for every occurence of the PasswordAuthentication rule with the following command:
sudo grep -ri passwordauthentication /etc/ssh/
This will show you every occurence of the rule along with it’s current value and the path to the file it is set in.