How to configure SSH agent to set user for second hop?

Is it possible to connect to a web server and then connect to a git server using SSH agent if the second hop needs a different user?

It works if I pass in the user name explicitly.

$ ssh web.example.com
# connects

  > ssh -T yellow@git.example.com
  > # connects

It does not work if I rely on the SSH config to set user.

$ ssh web.example.com
# connects

  > ssh -T git.example.com
  > # permission denied

Here is the SSH config on my machine.

Host web.example.com
  User blue
  ForwardAgent yes

Host git.example.com
  User yellow

In the debug output it says authenticating as blue even though the config sets the user to yellow for the host.

debug1: Authenticating to git.example.com:22 as 'blue'

Why does it use the wrong user? I don't want to hard code the user because then it does not work for the whole team to use the same deploy script.

0
задан 3 July 2018 в 22:13
1 ответ

Я предпочитаю явно устанавливать все настройки в моем ~ / .ssh / config с коротким псевдонимом для каждого хоста. Таким образом, мне не нужно будет использовать какие-либо флаги командной строки, и я могу просто ввести меньше и использовать ssh Destination и покончить с.

Host web
    Hostname web.example.com
    User blue
    ForwardAgent yes
    AddKeysToAgent yes
    UseKeychain yes                                  # Specific to OS X 
    IdentityFile ~/.ssh/id_rsa.blue

Host git
    Hostname git.example.com
    User yellow 
    ForwardAgent yes
    AddKeysToAgent yes
    UseKeychain yes                                  # Specific to OS X
    IdentityFile ~/.ssh/id_rsa.yellow
    ProxyJump web

ProxyJump - относительно новый параметр, который я считаю несколько более интуитивным в использовании, чем ProxyCommand . Теперь ssh git будет делать именно то, что вам нужно, сначала создайте сеанс, используя (скрытый) в качестве первого прыжка, из которого вы туннелируете на следующий прыжок с (скрытым), также можете использовать команду ProxyJump непосредственно из командная строка:

ssh -J blue@web.example.com yellow@git.example.com
2
ответ дан 4 December 2019 в 13:25

Теги

Похожие вопросы