Re: Can SSH Default to Different Usernames Based on Remote Host?
Jeff Stevens wrote:
Suppose I am working with three machines. I'm logged into host
"workstation" and I would like to ssh to hosts "remote0" and "remote1".
"id_dsa" and "id_dsa.pub" exist on "workstation". I've added
"id_dsa.pub" from "workstation" to "authorized_keys2" on hosts "remote0"
and "remote1". I've used "ssh-add" on "workstation" to add my private
key to the ssh agent. Nothing unusual here. Just wanted to be
Let's say my username on "workstation" is "jeff". My username on
"remote0" is also "jeff", however my username on "remote1" is "foo".
I can "ssh remote0" and am able to log in without further prompting.
All works well. On the other hand, I have to specify my username in
"ssh foo@remote1" when connecting to "remote1". This is, of course,
because my username on "workstation" and "remote1" differ.
I'm curious if there is a way I can configure ssh to automatically use
the username "foo" when connecting to "remote1".
The configuration file ~/.ssh/config is meant to do so: for further information:
Of course there are other solutions. I could use an alias or shell
script. I want to know if I can configure ssh itself to default to
different usernames per remote host.