
У меня есть настройка, в которой мне нужно сделать 2 прокси-прыжка, чтобы подключиться к моему серверу D
. По сути, из A
мне нужно подключиться к B
, из которого мне нужно подключиться к C
(который допускает только соединения с B
), откуда я затем могу подключиться к D
(который принимает только соединения с C
).
На B
, используя конфигурацию ssh, я могу подключиться, D
просто набрав ssh D
, поэтому я подумал, что могу использовать эту конфигурацию A
для подключения к D
:
Host B
hostname 127.0.0.1
user myUser
Port 43099
IdentityFile ~/.ssh/id_rsa
Host D
hostname D
ProxyJump B
а затем подключитесь из A
, чтобы подключиться к D
через ssh D
.
Однако вот какую ошибку я получаю:
debug1: Reading configuration data /home/MyUser/.ssh/config
debug1: /home/MyUser/.ssh/config line 17: Applying options for D
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Setting implicit ProxyCommand from ProxyJump: ssh -v -W '[%h]:%p' B
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Executing proxy command: exec ssh -v -W '[D]:22' B
debug1: Local version string SSH-2.0-OpenSSH_8.8
OpenSSH_8.8p1, OpenSSL 1.1.1m 14 Dec 2021
debug1: Reading configuration data /home/MyUser/.ssh/config
debug1: /home/MyUser/.ssh/config line 7: Applying options for B
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 43023.
debug1: Connection established.
debug1: identity file /home/MyUser/.ssh/id_rsa type 0
debug1: identity file /home/MyUser/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.6
debug1: compat_banner: match: OpenSSH_8.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 127.0.0.1:43023 as 'MyUser'
debug1: load_hostkeys: fopen /home/MyUser/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:to5+n56a6Zj+sbTnMghZGehX2OX5cn29HWbje55WJHU
debug1: load_hostkeys: fopen /home/MyUser/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '[127.0.0.1]:43023' is known and matches the ED25519 host key.
debug1: Found key in /home/MyUser/.ssh/known_hosts:45
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/MyUser/.ssh/id_rsa RSA SHA256:d6hsPtnc6TWfm9j5lOClBzD4ylE+ww/tg9BE7qP8DlE explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /home/MyUser/.ssh/id_rsa RSA SHA256:d6hsPtnc6TWfm9j5lOClBzD4ylE+ww/tg9BE7qP8DlE explicit
debug1: Server accepts key: /home/MyUser/.ssh/id_rsa RSA SHA256:d6hsPtnc6TWfm9j5lOClBzD4ylE+ww/tg9BE7qP8DlE explicit
Authenticated to 127.0.0.1 ([127.0.0.1]:43023) using "publickey".
debug1: channel_connect_stdio_fwd: D:22
debug1: channel 0: new [stdio-forward]
debug1: getpeername failed: Bad file descriptor
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem full
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: client_input_hostkeys: searching /home/MyUser/.ssh/known_hosts for [127.0.0.1]:43023 / (none)
debug1: client_input_hostkeys: searching /home/MyUser/.ssh/known_hosts2 for [127.0.0.1]:43023 / (none)
debug1: client_input_hostkeys: hostkeys file /home/MyUser/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Remote: /Users/Hendrik/.ssh/authorized_keys:3: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /Users/Hendrik/.ssh/authorized_keys:3: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
channel 0: open failed: connect failed: nodename nor servname provided, or not known
stdio forwarding failed
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535
Похоже, что конфигурация ssh B
вообще не читается.
Мой конфиг ssh B
выглядит так:
Host C
HostName C
User MyUser
ForwardX11Trusted yes
ForwardX11 yes
Host D
User MyUser
HostName D
ProxyCommand ssh %r@C -W %h:22
RemoteForward 26512 github.com:22
Compression yes
ForwardX11Trusted yes
ForwardX11 yes
DynamicForward 10080
ControlMaster auto
ControlPath ~/.ssh/masters/%C
Есть ли способ отредактировать конфигурацию SSH A
таким образом, чтобы я мог подключиться с A
помощью ?D
ssh D
решение1
При использовании proxy jump все ssh-подключения возникают на исходном клиенте (в данном случае A), а промежуточные узлы — это просто конечные точки туннеля. Поэтому в вашем случае вся конфигурация (включая файлы закрытых ключей) должна быть на A и выглядеть примерно так (при условии, что вы используете один и тот же файл идентификации для всех 3 хостов):
Host B
hostname 127.0.0.1
user myUser
Port 43099
IdentityFile ~/.ssh/id_rsa
Host C
ProxyJump B
IdentityFile ~/.ssh/id_rsa
# Any additional options for connecting to C
Host D
ProxyJump C
IdentityFile ~/.ssh/id_rsa
# Any additional options for connecting to D
Когда вы ssh D
, ssh-клиент на A выполнит следующую серию ssh-сеансов:
- A -> B (напрямую по сети)
- A -> C (туннелируется через соединение A->B, затем напрямую по сети от B к C)
- A -> D (туннелируется через соединение A->C (которое туннелируется через A->B), а затем напрямую по сети от C до D)