multiple ssh aliases is selecting wrong user when forwarding

Posted by Chris Beck on Super User See other posts from Super User or by Chris Beck
Published on 2014-06-07T14:39:21Z Indexed on 2014/06/07 15:28 UTC
Read the original article Hit count: 347

Filed under:

I'm following the dual identity procedure for bitbucket:

I have 2 bitbucket accounts ccmcbeck and chrisbeck. The former is personal, the latter is work.

On my local Mac, I have this in my ~/.ssh/config

Host *.work.com
  User chris
  ForwardAgent yes
  IdentityFile ~/.ssh/work_dsa
Host bitbucket-personal
  HostName bitbucket.org
  User ccmcbeck
  ForwardAgent no
  IdentityFile ~/.ssh/bitbucket_ccmcbeck_rsa
Host bitbucket-work
  HostName bitbucket.org
  User chrisbeck
  ForwardAgent no
  IdentityFile ~/.ssh/bitbucket_chrisbeck_rsa

On my local Mac I ssh -T all is good, I get:

$ ssh -T git@bitbucket-personal
logged in as ccmcbeck.
$ ssh -T git@bitbucket-work
logged in as chrisbeck.

On my local Mac, the ssh version is OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011

When I ssh foo.work.com to my Linux box, I get:

$ ssh-add -l
1024 ... /Users/chris/.ssh/work_dsa (DSA)
2048 ... /Users/chris/.ssh/bitbucket_ccmcbeck_rsa (RSA)
2048 ... /Users/chris/.ssh/bitbucket_chrisbeck_rsa (RSA)

On foo.work.com, I also have this in my ~/.ssh/config

Host bitbucket-personal
  HostName bitbucket.org
  User ccmcbeck
  ForwardAgent no
  IdentityFile ~/.ssh/bitbucket_ccmcbeck_rsa
Host bitbucket-work
  HostName bitbucket.org
  User chrisbeck
  ForwardAgent no
  IdentityFile ~/.ssh/bitbucket_chrisbeck_rsa

However, on foo.work.com when I ssh -T, it references the wrong User for git@bitbucket-work

$ ssh -T git@bitbucket-personal
logged in as ccmcbeck.
$ ssh -T git@bitbucket-work
logged in as ccmcbeck.

On foo.work.com, the ssh version is OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

Why is my configuration causing foo.work.com to reference the wrong User?

© Super User or respective owner

Related posts about ssh