12 January, 2023

Passwordless ssh Login

If you use ssh alot to log in to a remote server, you can skip typing in the password each time. I use Termux on mobile phone, so less typing is better. A cryptographic key pair is used for authentication where the public key is registered at the remote server once.

You need a cryptographic key on your local machine. Check if you have a public key file such as .ssh/id_rsa.pub in your home folder.

In Termux(on Android Phones) you need to install OpenSSH first with:

pkg install openssh

To create a new cryptographic key execute:

ssh-keygen -t rsa -b 4096

Use the default values.

Append the public key content to the remote file .ssh/authorized_keys with the following command:

cat .ssh/id_rsa.pub | ssh -t phyrum@tea.ch "cat - >> ./.ssh/authorized_keys"

In Linux you can use ssh-copy-id which does the same:

ssh-copy-id -i .ssh/id_rsa.pub phyrum@tea.ch

Now you can login such as ssh phyrum@tea.ch without entering a password.

Windows with PuTTY

On Windows with PuTTY you can use the same private key. There is alot more steps involved to do this, open PuTTYgen and

  1. Click Load to open the file-dialog
  2. Show all files
  3. Select the private key, in our case id_rsa (not the one showing as Microsoft Publisher Document)
  4. Click Save private key and give it a distinct name such as puttyprivatekey.ppk
  5. Open PuTTY and load your saved sesssion
  6. In Connection/SSH/Auth/, click Browse...
  7. Select the puttyprivatekey.ppk file
  8. Save the session and start the session without a password