[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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
detailed.

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".

Yes; refer to the manpage for ssh_config. In short, create $HOME/.ssh/config with an entrie like

Host remote1
User foo

Of course, as you can see in the manpage you can specify a whole range of options, not just the username.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



Reply to: