Accessing a remote SSH server typically requires entering a username and password. This method, known as PasswordAuthentication, is common but can become tedious for those who frequently connect to multiple servers. Repeatedly typing in credentials can slow down workflows and increase the likelihood of errors.

A more efficient approach is to use passwordless SSH authentication. This method allows users to log in automatically without entering a password. It is particularly useful for system administrators and developers who need quick and secure access to remote servers.

To set up passwordless SSH, you need to configure public-key authentication. This involves generating an SSH key pair, enabling PubkeyAuthentication on the server, and transferring the public key to the remote machine. Once configured, you can log in securely without a password, streamlining your remote access tasks.

Steps to enable passwordless login in SSH:

  1. Open the terminal on your local machine.
  2. Generate an SSH key pair if you do not 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. Ensure PubkeyAuthentication is enabled on the remote server.
    $ sudo grep PubkeyAuthentication /etc/ssh/sshd_config
    [sudo] password for user:
    PubkeyAuthentication yes

    Public key authentication is normally enabled by default.

  4. Transfer your public key to the remote SSH server.
    $ ssh-copy-id user@remote-host
    /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
    user@remote-host's password:
    
    Number of key(s) added: 2
    
    Now try logging into the machine, with:   "ssh 'user@remote-host'"
    and check to make sure that only the key(s) you wanted were added.
  5. Test the connection by logging in to the remote server.
    $ ssh user@remote-host
    Last login: Fri Jun 28 00:12:15 2019 from 192.168.111.135
    [user@remote-host ~]$

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

Discuss the article:

Comment anonymously. Login not required.