Prerequisites
- You have deployed a VPS with Ubuntu. (Vultr, Digital Ocean, Etc.) Here's a Referral Link for Vultr if you want to try them out. (no biggy if you don't want to though).
- You have installed PuTTY on your local Desktop.
- You have a separate user setup on your server with sudo privileges.
Create Your Keys
When you install PuTTY it will also come with an application called PuTTYgen. Launch PuTTYgen and follow the steps below.
- Keep the default settings of RSA and 2048 bits .
- Click Generate and move your mouse around until the key has been built.
- Once generated, Create a Key Passphrase.
- Then save the Public Key, and Private Key somewhere local on your computer.
- Keep the application open while we move onto the next step, so you can use the public key for copy/pasting.
Create the SSH Directory and File
Now that we have our keys generated, we are going to create the directory and file needed on our server. Open up a current remote connection to your server and follow the steps below.
WARNING: Do NOT run the directory and file creation commands with sudo privileges.
- Create a hidden directory called .ssh within your users home directory.
mkdir ~/.ssh
- Create a file called 'authorized_keys'
nano ~/.ssh/authorized_keys
- An empty file ready to be edited will be opened in your terminal. Copy/Paste the Public Key from the PuTTYgen application we left open.
- NOTE: if you closed the application by accident, just relaunch PuTTYgen and click Load. Navigate to your Public Key and load it into PuTTYgen.
- Exit and save the file. ctrl-x
- Finally, change the permissions for the directory and file with the following command.
chmod 700 -R ~/.ssh && chmod 600 ~/.ssh/authorized_keys
Test the SSH Connection
Now we are going to test out our SSH connection using PuTTY.
- Navigate to your Private Key File we saved earlier and Double Click on it.
- Enter your Passphrase you created earlier when prompted.
- Now, Launch the regular PuTTY application on your desktop.
- Enter your Server's IP address into the Host Name.
- Leave the rest of the default settings alone and Click Open.
- If this is your first time remotely connecting to this server you will be prompted by a security warning asking if you trust the server. You can select Yes. If you are interested in how you can actually verify this, follow my additional step below with the header Verify Remote Server (optional).
- A terminal window will open and prompt you for the user you would like to sign in with. Enter your user name.
- Next the magic happens. You will see your SSH key being Authenticated.
- Once that completes, you'll be logged in officially via SSH! =)
Verify Remote Server (optional)
When you first connect to your remote server you will be prompted to verify and confirm you trust the server you are connecting to. The prompt will show you a string that you can use to verify this connection with the steps below.
- Open a Local Connection to your server. Most VPS host provide a way to do this within the Servers Dashboard.
- Once connected locally, use the following commands to obtain strings you can match against the ones shown on the security warning prompt.
ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key
ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key -E md5
Thanks for Reading!
Top comments (0)