Goal

Assume we are using linux and openssh and we want to do an automatic login form “host A/user a” to “Host B/ user b” without entering your password every time.

How to do it?

  • Open a terminal.
  • log in to host A
  • Generating a pair of authentication keys: a@A:~$ ssh-keygen -t rsa
    • Enter file in which to save the key (/home/a/.ssh/id_rsa):
    • Created directory '/home/a/.ssh'.
    • Enter passphrase (empty for no passphrase):
    • Enter same passphrase again:
  • Now, your identification is saved in "/home/a/.ssh/id_rsa" and your public ey has been saved in "/home/a/.ssh/id_rsa.pub"
  • Now create a directory "~/.ssh" as user b on B. This directory may already exists.
    • a@A:~$ ssh b@B
    • mkdir -p .ssh
  • Finally you need to append a's new public key to the authorized keys for b@B as
    • a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
  • At this step, we are done! I usually add an alias to my ~/.bashrc file, for doing the whole ssh thing with just typing someWord! You can append this line to your ~/.bashrc file:
    • alias someWord="ssh b@B"
  • Voila!!