Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenSSH ignores User name set in config file

1,103 views
Skip to first unread message

Alexander Skwar

unread,
Aug 24, 2011, 8:21:42 AM8/24/11
to
Hello.

In my ~/.ssh/config, I've got:

# BOF
Host *
User local

Host foo
HostName 10.20.30.40
User i
# EOF

When I do a "ssh foo", it tries to connect to 10.20.30.40 using
the username "local". When I remove the "Host *" lines, it tries
to connect with the username "i".

You can find a "ssh -v -v -v foo" output at http://pastebin.com/4YuFD8i4

Why does SSH do that?

I would like SSH to connect to "foo" using the username "i" and
not "local".

As to why do I have a "Host *" entry: Usually, I need/want to
connect to hosts using the username "local" (yep, l o c a l). This
is *NOT* my local username on my workstation (it's "ask"). But
for some hosts (like the "foo" one there), I'd like to connect using
a different username ("i" in this case). I know that I could of course
use "ssh i@foo", but that doesn't answer the quetion, why the "User"
line seems to be ignored...

ask@ewzw032:~> uname -a
Linux ewzw032 2.6.37.6-0.7-desktop #1 SMP PREEMPT 2011-07-21 02:17:24
+0200 x86_64 x86_64 x86_64 GNU/Linux

ask@ewzw032:~> ssh -V
OpenSSH_5.8p1, OpenSSL 1.0.0c 2 Dec 2010

ask@ewzw032:~> cat /etc/SuSE-brand
openSUSE
VERSION = 11.4

Thanks,
Alexander

Gilles Pion

unread,
Aug 24, 2011, 10:37:02 AM8/24/11
to
Ref: <57fbde81-9c36-4753...@d25g2000yqh.googlegroups.com> de
Alexander Skwar

>Hello.
>
>In my ~/.ssh/config, I've got:
>
># BOF
>Host *
> User local
>
>Host foo
> HostName 10.20.30.40
> User i
># EOF
>
>When I do a "ssh foo", it tries to connect to 10.20.30.40 using
>the username "local". When I remove the "Host *" lines, it tries
>to connect with the username "i".
>

This is normal regarding how openssh parse its config file: the first option
inside a matching "Host" section "wins" against all next lines with same option

Since the "Host *" matches *every* hostname, "User=local" option will always be
used in your case.

Simply put least specific host sections at the end of the file, like this:
# BOF


Host foo
HostName 10.20.30.40
User i

# global catch-all default section
Host *
User local
# EOF

--
Gilles Pion

Alexander Skwar

unread,
Aug 25, 2011, 2:27:28 AM8/25/11
to
On 24 Aug., 16:37, Gilles Pion <nosuchu...@nosuchdomain.com> wrote:

> This is normal regarding how openssh parse its config file: the first option
> inside a matching "Host" section "wins" against all next lines with same option

[…]


> Simply put least specific host sections at the end of the file, like this:

Thanks a lot, this way it works :)

Cheers,
Alexander

0 new messages