Skip to content

SSH Connection with No Password

Christopher Hopkins edited this page Nov 9, 2015 · 9 revisions

Useful if you frequently connect to a remote machine using ssh.

Prerequisites:

  • SSH server running on remote machine (Obvious)
  • ssh client on you local machine

Step 1: Generate a ssh key pair on the local machine

$ ssh-keygen -t rsa -b 4096

The -t option allows you to specify the key type. The -b option allows you to specify the key size.

You will be prompted to enter a filename and password (both can be left default/blank).

Step 2: Copy the public key to the remote machine

 $ scp .ssh/id_rsa.pub username@remote_machine:remote_pub_key

This will copy the key from the local machine to the home directory of the user on the remote machine.

Step 3: Append the copied key to the '.ssh/authorized_keys file'

Login to the remote machine and use the following command:

 $ cat remote_pub_key >> .ssh/authorized_keys

Step 4: Attempt a SSH connection using the installed keys

 $ ssh user@remote_machine

If it does not work, there may be some changes on the remote server.

  • You may need to change the permissions on the 'authorized_keys' file on the remote_machine:

     $ chmod 640 authorized_keys
    

Clone this wiki locally