The usual way to log in to remote servers using SSH is via the challenge–response protocol by the use of username and password combination.

Yo can also log in using public and private key pair method and when configured, can be used to passwordlessly log in to remote SSH servers; which could be a nice convenience and useful for automation work.

You can configure passwordless SSH login with the use of public key authentication method from the terminal.

Steps to configure passwordless SSH login:

  1. Launch terminal application.
  2. Generate an SSH key pair on the local host if you don't already have one.
    $ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/user/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/user/.ssh/id_rsa.
    Your public key has been saved in /home/user/.ssh/id_rsa.pub.
    ##### snipped

    Make sure to not set any passphrase for the key pair

  3. Enable public key authentication in the remote SSH server.
    $ sudo grep PubkeyAuthentication /etc/ssh/sshd_config
    [sudo] password for user:
    PubkeyAuthentication yes

    Public key authentication is normally enabled by default.

  4. Copy your SSH public key from local host to the SSH server.
    $ ssh-copy-id [email protected]
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 2 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    [email protected]'s password:
    
    Number of key(s) added: 2
    
    Now try logging into the machine, with:   "ssh '[email protected]'"
    and check to make sure that only the key(s) you wanted were added.
  5. Log in to the remote server to test.
    $ ssh [email protected]
    Last login: Fri Jun 28 00:12:15 2019 from 192.168.111.135
    [[email protected] ~]$

    You will no longer be prompted for password when logging in to the server.

Guide compatibility:

Operating System
Ubuntu Linux
Debian Linux
Red Hat Enterprise Linux
Fedora Linux
CentOS Linux
openSUSE Linux
SUSE Linux Enterprise Server
FreeBSD
OpenBSD
NetBSD
macOS
Share this guide!
Discuss the article:

Comment anonymously. Login not required.

Share!