Почему мои ключи SSH не пересылаются должным образом?

Я пытаюсь выполнить ssh с моей машины на другую машину, а оттуда на третью машину. Когда я делаю это вручную, это работает так:

localhost$ scp ~/.ssh/id_rsa myuser@myhost.something.something.com:.
localhost$ ssh myuser@myhost.something.something.com
myhost.something.something.com$ ssh -i id_rsa myuser@10.25.100.42
10.25.100.42$ 

Но я хотел бы сделать это напрямую, за один шаг. И я хочу, чтобы мои SSH-ключи от localhost пересылались на третью машину. Я думал, это сработает, но это не так:

localhost$ ssh -A -t myuser@myhost.something.something.com ssh 10.25.100.42
Permission denied (publickey).
Connection to myhost.something.something.com closed.

Почему? Как я могу сделать это одной командой с localhost ? Вот некоторые подробности, которые вы можете увидеть, когда я использую подробный флаг:

localhost$ ssh -v -A -t myuser@myhost.something.something.com ssh 10.25.100.42

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myhost.something.something.com [X.X.X.X] port 22.
debug1: Connection established.
debug1: identity file /home/myuser/.ssh/id_rsa type 1
debug1: identity file /home/myuser/.ssh/id_rsa-cert type -1
debug1: identity file /home/myuser/.ssh/id_dsa type -1
debug1: identity file /home/myuser/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 62:d2:58:47:f7:c6:21:b4:a1:b0:cf:4e:44:42:e4:9a
debug1: Host 'myhost.something.something.com' is known and matches the RSA host key.
debug1: Found key in /home/myuser/.ssh/known_hosts:255
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myuser/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to myhost.something.something.com ([X.X.X.X]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Requesting authentication agent forwarding.
debug1: Sending command: ssh 10.25.100.42
debug1: client_input_channel_open: ctype auth-agent@openssh.com rchan 2 win 65536 max 16384
debug1: channel 1: new [authentication agent connection]
debug1: confirm auth-agent@openssh.com
Permission denied (publickey).
debug1: channel 1: FORCE input drain
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 2
debug1: channel 1: free: authentication agent connection, nchannels 1
Connection to myhost.something.something.com closed.
Transferred: sent 3532, received 3312 bytes, in 4.4 seconds
Bytes per second: sent 796.1, received 746.6
debug1: Exit status 255
2
задан 25 March 2016 в 05:08
1 ответ

Если вы хотите перенаправить соединение с вашим агентом аутентификации, вам необходимо, чтобы агент аутентификации работал на вашем компьютере. Вы можете проверить это с помощью ssh-add -l . Если он не запущен, запустите его и добавьте ключи:

eval `ssh-agent`
ssh-add ~/.ssh/id_rsa
# or other keys you want to use from the other server

, а затем после подключения к другому серверу с помощью переключателя -A вы сможете далее аутентифицироваться с помощью этого ключа:

local     $ ssh -A myuser@myhost.something.something.com
something $ ssh-add -l                     # should list your key
something $ ssh 10.25.100.42

Но на самом деле вы пытаетесь достичь чего-то другого. Вы хотите использовать первый хост как переходник для подключения ко второму, и это можно сделать намного удобнее с помощью ProxyCommand:

ssh -oProxyCommand="ssh -W 10.25.100.42:22" myuser@myhost.something.something.com

или лучше с .ssh / config :

Host something
  Hostname myhost.something.something.com
  User myuser
Host second
  Hostname 10.25.100.42
  User myuser
  ProxyCommand ssh -W %h:%p something

, а затем вы попасть туда, просто используя

ssh second
4
ответ дан 3 December 2019 в 09:59

Теги

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