How to configure SSH Key authentication on a remote server

September 4, 2025 / Security and Backups

In this guide, we have explained how to add your SSH key to a remote server.

Passwordless authentication between your local computer and a distant server is made possible using Secure Shell (SSH) keys. This improves connection convenience and security.

Follow the guide:

  1. To check for an existing SSH key, run the following command on your local machine:
    ls ~/.ssh/id_rsa.pub
  2. If the file exists, you already have a public key. If not, you need to generate one using the following command:
    ssh-keygen -t rsa -b 4096 -C [email protected]
  3. Press Enter to save in the default location (~/.ssh/id_rsa).
  4. Optionally set a passphrase for added security.
  5. Your keys will be saved as:
    1. Private key ? ~/.ssh/id_rsa
    2. Public key ? ~/.ssh/id_rsa.pub
  6. Copy the Public Key to the Remote Server using the ssh-copy-id command:
    ssh-copy-id user@remote_server_ip

    Replace ‘user’ with your remote username and ‘remote_server_ip’ with the server’s IP address.

  7. If ssh-copy-id is not available, you can copy manually:
    cat ~/.ssh/id_rsa.pub | ssh user@remote_server_ip “mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys”
  8. Adjust Permissions on the Remote Server by running:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

    This ensures the SSH directory and key file are properly secured.

  9. Now to test the SSH login, connect to the server without a password:
    ssh user@remote_server_ip
  10. If successful, you are logged in using SSH keys.

You can eliminate the need for a password and increase security by linking your SSH key to the remote server. This will be especially helpful for frequent connections and automated routines.

Configured SSH key authentication? Learn How to import an SSH key via root access

Spread the love