Login SSH without typing password every time
- create public and private keys on local-host (debian)
jason@debian$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/jason/.ssh/id_rsa):[Enter key] Enter passphrase (empty for no passphrase): [Press enter key] Enter same passphrase again: [Pess enter key] Your identification has been saved in /home/jason/.ssh/id_rsa. Your public key has been saved in /home/jason/.ssh/id_rsa.pub. The key fingerprint is: 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jason@debian
This command creates two RSA key files, id_rsa for private key, and id_rsa.pub for public key, in the directory $HOME/.ssh.
- copy the public key file to remote-host (fedora) using ssh-copy-id
jason@debian$ ssh-copy-id -i ~/.ssh/id_rsa.pub fedora jason@fedora's password: jason@fedora$
Now try logging into the remote machine (fedora)
jason@debina$ ssh fedora Last login: Thu Feb 16 11:45:20 2017 from debian jason@fedora$
Notice that ssh does not ask for password. Check the authorized_key to make sure we haven’t added extra keys that you weren’t expecting.
jason@fedora$ cat .ssh/authorized_keys
ref – 3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id
In case ssh-copy-id is not available (for example, on mingw), as an alternated solution, you can manually copy the public key file (id_rsa.pub) to the remote host, and add the content as a record into $HOME/.ssh/authorized_keys. The file is a text file, so if it doesn’t exist, you can create it with a text editor. Don’t forget to change the mode to 644, otherwise sshd won’t use it.
Define host aliases in SSH config
Following lines in ~/.ssh/config define two aliases for the host staging.example.com
host foo bar # aliases separated by whites hostname staging.example.com