SSH Key-Based Authentication
Last updated
Last updated
Now we are going to set up a way to authenticate your log in with a specific SSH key for extra security.
If you haven't already, that should come with PuTTYgen, the Key Generator.
Start Key Generation: Click the "Generate" button.
Move the Mouse Cursor: To create randomness, move your mouse cursor around the blank area in the PuTTYgen window. This process helps generate a secure key.
Completion: Once the progress bar is full and the key is generated, PuTTYgen will display the public key.
Add a Passphrase: Enter a strong passphrase in the "Key passphrase" and "Confirm passphrase" fields. This adds an extra layer of security by encrypting your private key.
Back in your Ubuntu terminal, let's switch to the notarb user.
We are going to take the copied Public Key text and paste it into the authorized_keys file. We'll use nano to edit the file.
We'll now set up PuTTY so it will log in using your key.
Open PuTTY
Launch PuTTY: Open PuTTY from the Start menu or desktop shortcut.
Enter Connection Details
Under Session Settings, enter the following:
Host Name (or IP address): Enter your remote server's hostname or IP.
Port: Typically 22
for SSH.
Connection Type: Ensure SSH
is selected.
Save the Session
Under "Saved Sessions", enter a name.
Click "Save" to reuse these settings in the future.
Specify the Private Key for Authentication
Navigate to SSH Authentication Settings:
In the left sidebar, expand "Connection" > "SSH" > "Auth".
Browse for Private Key:
Click "Browse..." next to "Private key file for authentication".
Select the .ppk
file you saved earlier (e.g., id_rsa.ppk
).
Save the Session:
Select the Session category and save the session again for the changes to take effect.
Start the Connection:
Click "Open" to initiate the SSH session.
If prompted with a security alert about the server's host key, verify it and click "Yes" to proceed.
Login with Username:
When prompted, enter your username on the remote server.
If You Set a Passphrase: You'll be prompted to enter the passphrase for your private key.
Successful Authentication:
Upon successful authentication, you'll gain access to the remote server without needing to enter your password.
Before proceeding, ensure you have at least one non-root user account with sudo privileges. This is crucial to prevent being locked out of your server. We've already set up notarb user, so make sure we can already log in with notarb.
Time to configure our login so we don't have to enter a password every time and instead use our key.
Open up another terminal and try accessing your server again. Ensure that the following settings are in place:
Connection>Data>Auto-login username: notarb
Connection>SSH>Auth>Credentials>Private key for authentication: set to your private key
You should be able to log in without having to enter a password
Now that we've ensured that we can log in with another user, we can safely disable root login access remotely.
You can now try to log in using the root user and you should get an Access Denied
response. Time to set up firewall and login protection.