Using %n and other options in ssh_config IdentityFile

Milosz Kosmider milosz at milosz.ca
Thu Jan 1 10:40:35 EST 2015


Hi folks,

The ssh_config man page specifies that the IdentityFile directive can
expand a number of special character sequences into useful values, for
example %h into the value of the HostName directive. This is great, but I
am finding that the ability to expand these variables under various
directives is quite spotty:

http://www.dtucker.net/openssh/percent_expand_opts.html

This chart possibly no longer reflects the status quo, but it paints the
intended picture. In particular, one feature I find is missing is the
ability to use %n (host name as specified on command line) in my
IdentityFile and User directives. That is the naming scheme I have been
using for my identity files and users for years now, and it has resulted in
a rather repetitive .ssh/config file that I would like to DRY up a little.
Allowing %n in the above directives would allow me to replace this:

Host *
  IdentitiesOnly yes
  PreferredAuthentications publickey

Host superduper
  HostName superduper.com
  User superduper
  IdentityFile ~/.ssh/supersuper.id_rsa

Host ultramega
  HostName ultramega.com
  User ultramega
  IdentityFile ~/.ssh/ultramega.id_rsa

Host differentuser
  HostName differentuser.com
  User someonelse
  IdentityFile ~/.ssh/differentuser.id_rsa

with this:

Host *
  IdentitiesOnly yes
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/%n.id_rsa
  User %n

Host superduper
  HostName superduper.com

Host ultramega
  HostName ultramega.com

Host differentuser
  HostName differentuser.com
  User someonelse

Thoughts? Is it reasonable? Is it feasible? If you folks think it's a good
idea, but no one on the inside has the bandwidth to do it, I am willing to
learn the ropes and submit a code change, but I cannot find the process for
this on the http://www.openssh.com/ website.

Cheers,
Milosz

System details:

   - OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
   - Ubuntu 14.04.1 LTS


More information about the openssh-unix-dev mailing list