I’ve got several domains hosted at the same hosting company, and the company provides SSH access for each of them with a different user name, but with the same SSH server address. As I’m using key-based login to the server (see also my post here) I ran into the following problem: How do I set up my SSH config file such that it knows which key to use for which user name?
It turns out that the solution is easy (thanks Kelvin!): if you use the %r
variable in the ~/.ssh/config
file it contains the user name which you used when logging in. Similarly, the %h
contains the host name you used on the command line. So all I needed to do was to create entries like this:
Host ssh.myhoster.com IdentityFile ~/.ssh/hosting-%r.key
and make sure that the corresponding key files are named hosting-domain1.key
, hosting-domain2.key
, etc. and then log in using a command like ssh domain1@ssh.myhoster.com
.
Leave a Reply