How to Enable SSH Public Key Authentication

October 16, 2023 / How-to Guide

This article describes how to enable secure shell (SSH) public key authentication.

Steps:

  1. Log in to the server.
  2. Confirm that the user exists-
    ‘getent passwd <username>’
  3. Check the value assigned to the AuthorizedKeysFile parameter in the /etc/ssh/sshd_config file to locate the specific file where the key is stored-
    ‘grep AuthorizedKeysFile /etc/ssh/sshd_config’
    Note- By default, the location is ~/.ssh/authorized_keys in the user’s primary home directory.
  4. Navigate to the user’s home directory.
    ‘cd /directory-path’
    Note- Replace “directory-path” with the path to the user’s home directory.
  5. For the .ssh/ directory, check permission levels. It should have 0700 permissions and be possessed by the user.
    ‘ls .ssh’

    1. In the event that the directory does not exist, create it and configure the permissions to 0700.
      ‘mkdir -m 700 .ssh’
    2. If the directory exists, you can set possession distinctly-
      ‘chmod 700 .ssh/’
      ‘chown -R username:username /path/to/home/.ssh’
  6. Shift to .ssh/ directory and authorized_keys file-
    ‘‘‘cd .ssh/
    vim authorized_keys
    ll’’’
  7. Append the SSH Public Key to the end of the authorized_keys file.
    ‘vim authorized_keys’
  8. Modify permissions to 600 and confirm appropriate ownership of the file-
    ‘chmod 600 authorized_keys’
    ‘chown -R username:username authorized_keys’

This way, you can enable secure shell (SSH) public key authentication. If you get into any problem, seek help from our technical support team at your earliest.

Spread the love