How to: Setting up key based authentication
  • 09 Aug 2022
  • 1 Minute to read
  • Dark
    Light

How to: Setting up key based authentication

  • Dark
    Light

Article summary

The following guide shows how to setup key based authentication for Linux servers


1. Create your SSH Key (On your local machine - Guides: Windows | Linux

2. Copying an SSH Public Key to Your Server
There are multiple ways to upload your public key to your remote SSH server. The method you use depends largely on the tools you have available and the details of your current configuration.

The location this needs to be uploaded to: ~/.ssh directory name: authorized_keys

For Linux and Mac users this can be done with;

ssh-copy-id username@remote_host


3. Authenticating to Your Server Using SSH Keys
If you have successfully completed coping your ssh public key to your server, you should be able to log into the remote host without the remote account’s password.

The process to login is;

ssh username@remote_host


4. Disabling Password Authentication on your Server
If you were able to log in to your account using SSH without a password, you have successfully configured SSH key-based authentication to your account. However, your password-based authentication mechanism is still active.

sudo nano /etc/ssh/sshd_config

Inside the file, search for a directive called PasswordAuthentication. This may be commented out. Uncomment the line by removing any # at the beginning of the line, and set the value to no. This will disable your ability to log in through SSH using account passwords:

Save and close the file when you are finished 

5. Restart the SSH Service
To implement the changes you've just made, you must restart the service.

On most Linux distributions, you can issue the following command to do that:

sudo systemctl restart sshd

After completing this step, you’ve successfully transitioned your SSH daemon to only respond to SSH keys.


















Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence