Posts tagged ‘authentification’

Using zsh as default shell is perfect. Using grml-zsh stuff to configure it, even better. Using XTaran’s config, way better. Using your own config, invaluable. Now, there is one thing that always bothered me: having all hosts I usually deal with in my ~/.ssh/config in order to have tab completion (and short names). I wanted to improve the situation and was kindly pointed in a different direction by Myon, namely to just use the ~/.ssh/known_hosts for tab completion. How about that?

I started playing around with the config and, as it turns out, Axel already has something ready. Unfortunately, it didn’t fulfill all my needs yet. That is because I have multiple known_hosts files. Martin already filed a bug to have ssh read ~/.ssh/known_hosts.d/* but that isn’t resolved yet either, even though upstream is aware of it. I thus had to point tab completion and ssh to multiple files by hand. But that’s not too bad for now. Let’s have a look:

What am I doing? Well, we need to deactivate the hashing of known hosts. Otherwise your known_hosts files aren’t readable as needed. Then you define your known_hosts files for the domains you care about. Pretty straight forward.

Now, how about tab completion in zsh? Well, easy part actually:

[ -f ~/.ssh/config ] && : ${(A)ssh_config_hosts:=${${${${(@M)${(f)"$(

What's here? We read and parse your ~/.ssh/config for configured hosts, then we parse all your known_hosts files which are for me: ~/.ssh/known_hosts, ~/.ssh/known_hosts.work, and ~/.ssh/known_hosts.debian. And lastly, all is added to zsh completion for hosts. That actually works. :)