Arkanis Development


Comfortable console SSH login with private keys


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…

Leave a new comment

Having thoughts on your mind about this stuff here? Want to tell me and the rest of the world your opinion? Write and post it right here. Be sure to check out the format help (focus the large text field) and give the preview button a try.


Format help

Please us the following stuff to spice up your comment.

An empty line starts a new paragraph. ---- print "---- lines start/end code" ---- * List items start with a * or -

Just to keep your skill sharp and my comments clean.