Comfortable console SSH login with private keys
Vom 7. Dezember 2009
On the virtual machines of my university SSH public / private keys are used for authentication. I usually connect to other servers using the ssh program in the terminal which looks like this:
ssh host
Pretty easy and straight forward. This command tries to log in at host with your current user name and asks you for a password.
When using public / private keys things are different. Your public key is stored on the server and the private key is on your PC. Instead of a password these keys are then used to authenticate you on the server. The only annoying thing is, that the ssh program first tries to log in via the normal password method. It then needs some time (several seconds) to figure out that the server does not support this method. A nice way to avoid this waiting time is to tell ssh to directly use the publickey method:
ssh -o PreferredAuthentications=publickey host
This command (found here) tries directly and only the privatekey method. However for a lazy programmer like me it’s a bit to much to type. One way to satisfy you laziness on the command line are bash aliases, kind of named shortcuts for often used commands. You can drop this line into the .bash_aliases file in your home directory:
alias sshpk='ssh -o PreferredAuthentications=publickey'
Whenever you know open a terminal and type in sshpk bash replaces this shortcut with “ssh -o PreferredAuthentications=publickey”. So I’m now able to lazily log into a host which uses SSH public / private keys:
sshpk host
Nice and short.
I know that there are other tools to keep track of many SSH logins. SSHMenu is one of them and I used it several times. However it never survived the natural selection of occasional reinstallations of my machine…
Abgelegt in: Sonstiges