How to setup passwordless ssh

  1. Check whether you have a public RSA key to share on your local computer. This means that you should have a file named ~/.ssh/id_rsa.pub. If so, skip next step.

  2. If you don't have a public RSA key, generate one using the following command accepting all default suggestions by pressing Enter:

    # Accept all defaults
    ssh-keygen -t rsa
    
  3. Create a profile for the remote computer on your local computer by adding the following to your ~/.ssh/config file. Create this file if it does not exist. Note that you need to know the IP address of the remote machine you are logging onto (Can be gotten by typing hostname -I on the remote machine). Replace the machine name (anything you want), username and IP address below as appropriate.

    # Common Lab Computer
    Host REMOTE
    User REMOTE_USERNAME
    HostName XXX.XXX.XX.XXX
    Compression yes
    ForwardX11 yes
    ControlMaster auto
    ControlPath ~/.ssh/%r@%h:%p
    ServerAliveInterval 15
    ServerAliveCountMax 3
    
  4. Create a ~/.ssh directory on the remote computer if it does not exist already (You can log on once with password a check if this directory exists). If this directory exists, skip this step. Replace REMOTE below with the name of the computer you are logging onto (that one you gave in the HOST field above).

    ssh REMOTE mkdir -p .ssh
    
  5. Send your public RSA key to the remote computer. Replace REMOTE below with the name of the computer you are logging onto (that one you gave in the HOST field above).

    # Send your public key to REMOTE
    cat .ssh/id_rsa.pub | ssh REMOTE 'cat >> .ssh/authorized_keys'
    
  6. Now you should be able to do ssh REMOTE and login without a password.