【发布时间】:2022-01-07 15:16:10
【问题描述】:
我有一台 DestHost、一台 JumpHost 和一台笔记本电脑。我想通过 JumpHost 使用隧道从笔记本电脑连接 DestHost 上的 Jupyter 笔记本。
这是我的 ~/.ssh/config
Host JumpAlias
User user_jump
Port 10002
HostName JumpHost
Host DestAlias
ServerAliveInterval 60
User user_dest
Port 10001
HostName DestHost
ProxyCommand ssh -W %h:%p JumpAlias
那我可以
ssh DestAlias
并以 user_dest 身份成功登录 DestAlias。
然后我想连接到 DestHost 上的 Jupyter notebook,所以我建立了一个隧道
ssh -N -f -L 8888:localhost:8888 DestAlias
隧道已经建成,但它不起作用。我想如果我可以登录到主机,那么我可以建立一个到主机的隧道。我能做什么?
这是日志
(base) ➜ ~ ssh -N -f -L 8888:localhost:8888 dest_host_alias -vvv
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/this_is_user/.ssh/config
debug1: /Users/this_is_user/.ssh/config line 17: Applying options for dest_host_alias
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug2: resolve_canonicalize: hostname 111.111.111.111 is address
debug1: Executing proxy command: exec ssh -W 111.111.111.111:12345 tiaoban
debug1: identity file /Users/this_is_user/.ssh/id_rsa type 0
debug1: identity file /Users/this_is_user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/this_is_user/.ssh/id_dsa type -1
debug1: identity file /Users/this_is_user/.ssh/id_dsa-cert type -1
debug1: identity file /Users/this_is_user/.ssh/id_ecdsa type -1
debug1: identity file /Users/this_is_user/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/this_is_user/.ssh/id_ed25519 type -1
debug1: identity file /Users/this_is_user/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/this_is_user/.ssh/id_xmss type -1
debug1: identity file /Users/this_is_user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version SSHD_0.7.6
debug1: no match: SSHD_0.7.6
debug2: fd 5 setting O_NONBLOCK
debug2: fd 4 setting O_NONBLOCK
debug1: Authenticating to 111.111.111.111:12345 as 'user_sensitive'
debug3: put_host_port: [111.111.111.111]:12345
debug3: hostkeys_foreach: reading file "/Users/this_is_user/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /Users/this_is_user/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys from [111.111.111.111]:12345
debug3: order_hostkeyalgs: prefer hostkeyalgs: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-dss,ssh-rsa
debug2: ciphers ctos: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: ciphers stoc: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: MACs ctos: hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib,zlib@openssh.com
debug2: compression stoc: none,zlib,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ssh-rsa SHA256:seems_sensitive_so_block_it/g
debug3: put_host_port: [111.111.111.111]:12345
debug3: hostkeys_foreach: reading file "/Users/this_is_user/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /Users/this_is_user/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys from [111.111.111.111]:12345
debug1: Host '[111.111.111.111]:12345' is known and matches the RSA host key.
debug1: Found key in /Users/this_is_user/.ssh/known_hosts:2
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /Users/this_is_user/.ssh/id_rsa RSA SHA256:seems_sensitive_so_block_it2+sR4 agent
debug1: Will attempt key: /Users/this_is_user/.ssh/id_dsa
debug1: Will attempt key: /Users/this_is_user/.ssh/id_ecdsa
debug1: Will attempt key: /Users/this_is_user/.ssh/id_ed25519
debug1: Will attempt key: /Users/this_is_user/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/this_is_user/.ssh/id_rsa RSA SHA256:seems_sensitive_so_block_it2+sR4 agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /Users/this_is_user/.ssh/id_rsa RSA SHA256:seems_sensitive_so_block_it2+sR4 agent
debug3: sign_and_send_pubkey: RSA SHA256:seems_sensitive_so_block_it2+sR4
debug3: sign_and_send_pubkey: signing using ssh-rsa
debug3: send packet: type 50
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
Authenticated to 111.111.111.111 (via proxy).
debug1: Local connections to LOCALHOST:8888 forwarded to remote address localhost:8888
debug3: channel_setup_fwd_listener_tcpip: type 2 wildcard 0 addr NULL
debug3: sock_set_v6only: set socket 6 IPV6_V6ONLY
debug1: Local forwarding listening on ::1 port 8888.
debug2: fd 6 setting O_NONBLOCK
debug3: fd 6 is O_NONBLOCK
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8888.
debug2: fd 7 setting O_NONBLOCK
debug3: fd 7 is O_NONBLOCK
debug1: channel 1: new [port listener]
debug1: forking to background
debug1: Entering interactive session.
debug1: pledge: proc
这是在chrome中访问jupyter url,关闭隧道后的日志。
(base) ➜ ~ debug1: Connection to port 8888 forwarding to localhost port 8888 requested.
debug2: fd 8 setting TCP_NODELAY
debug3: fd 8 is O_NONBLOCK
debug3: fd 8 is O_NONBLOCK
debug1: channel 2: new [direct-tcpip]
debug3: send packet: type 90
debug1: Connection to port 8888 forwarding to localhost port 8888 requested.
debug2: fd 9 setting TCP_NODELAY
debug3: fd 9 is O_NONBLOCK
debug3: fd 9 is O_NONBLOCK
debug1: channel 3: new [direct-tcpip]
debug3: send packet: type 90
debug3: receive packet: type 91
debug2: channel 2: open confirm rwindow 32000 rmax 35000
debug3: receive packet: type 91
debug2: channel 3: open confirm rwindow 32000 rmax 35000
debug2: channel 2: read<=0 rfd 8 len 0
debug2: channel 2: read failed
debug2: channel 2: chan_shutdown_read (i0 o0 sock 8 wfd 8 efd -1 [closed])
debug2: channel 2: input open -> drain
debug2: channel 2: ibuf empty
debug2: channel 2: send eof
debug3: send packet: type 96
debug2: channel 2: input drain -> closed
debug2: channel 2: rcvd adjust 97415
debug3: receive packet: type 96
debug2: channel 2: rcvd eof
debug2: channel 2: output open -> drain
debug2: channel 2: obuf empty
debug2: channel 2: chan_shutdown_write (i3 o1 sock 8 wfd 8 efd -1 [closed])
debug2: channel 2: output drain -> closed
debug2: channel 2: send close
debug3: send packet: type 97
debug3: channel 2: will not send data after close
debug3: receive packet: type 97
debug2: channel 2: rcvd close
debug3: channel 2: will not send data after close
debug2: channel 2: is dead
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65218 to ::1 port 8888, nchannels 4
debug3: channel 2: status: The following connections are open:
#2 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65218 to ::1 port 8888 (t4 r43 i3/0 o3/0 e[closed]/0 fd 8/8/-1 sock 8 cc -1)
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65219 to ::1 port 8888 (t4 r44 i0/0 o0/0 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug1: Connection to port 8888 forwarding to localhost port 8888 requested.
debug2: fd 8 setting TCP_NODELAY
debug3: fd 8 is O_NONBLOCK
debug3: fd 8 is O_NONBLOCK
debug1: channel 2: new [direct-tcpip]
debug3: send packet: type 90
debug2: channel 3: read<=0 rfd 9 len 0
debug2: channel 3: read failed
debug2: channel 3: chan_shutdown_read (i0 o0 sock 9 wfd 9 efd -1 [closed])
debug2: channel 3: input open -> drain
debug2: channel 3: ibuf empty
debug2: channel 3: send eof
debug3: send packet: type 96
debug2: channel 3: input drain -> closed
debug3: receive packet: type 91
debug2: channel 2: open confirm rwindow 32000 rmax 35000
debug2: channel 3: rcvd adjust 97441
debug3: receive packet: type 96
debug2: channel 3: rcvd eof
debug2: channel 3: output open -> drain
debug2: channel 3: obuf empty
debug2: channel 3: chan_shutdown_write (i3 o1 sock 9 wfd 9 efd -1 [closed])
debug2: channel 3: output drain -> closed
debug2: channel 3: send close
debug3: send packet: type 97
debug3: channel 3: will not send data after close
debug3: receive packet: type 97
debug2: channel 3: rcvd close
debug3: channel 3: will not send data after close
debug2: channel 3: is dead
debug2: channel 3: garbage collecting
debug1: channel 3: free: direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65219 to ::1 port 8888, nchannels 4
debug3: channel 3: status: The following connections are open:
#2 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65220 to ::1 port 8888 (t4 r45 i0/0 o0/0 e[closed]/0 fd 8/8/-1 sock 8 cc -1)
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65219 to ::1 port 8888 (t4 r44 i3/0 o3/0 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug1: Connection to port 8888 forwarding to localhost port 8888 requested.
debug2: fd 9 setting TCP_NODELAY
debug3: fd 9 is O_NONBLOCK
debug3: fd 9 is O_NONBLOCK
debug1: channel 3: new [direct-tcpip]
debug3: send packet: type 90
debug2: channel 2: read<=0 rfd 8 len 0
debug2: channel 2: read failed
debug2: channel 2: chan_shutdown_read (i0 o0 sock 8 wfd 8 efd -1 [closed])
debug2: channel 2: input open -> drain
debug2: channel 2: ibuf empty
debug2: channel 2: send eof
debug3: send packet: type 96
debug2: channel 2: input drain -> closed
debug2: channel 2: rcvd adjust 97441
debug3: receive packet: type 91
debug2: channel 3: open confirm rwindow 32000 rmax 35000
debug3: receive packet: type 96
debug2: channel 2: rcvd eof
debug2: channel 2: output open -> drain
debug2: channel 2: obuf empty
debug2: channel 2: chan_shutdown_write (i3 o1 sock 8 wfd 8 efd -1 [closed])
debug2: channel 2: output drain -> closed
debug3: receive packet: type 97
debug2: channel 2: rcvd close
debug3: channel 2: will not send data after close
debug2: channel 2: send close
debug3: send packet: type 97
debug2: channel 2: is dead
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65220 to ::1 port 8888, nchannels 4
debug3: channel 2: status: The following connections are open:
#2 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65220 to ::1 port 8888 (t4 r45 i3/0 o3/0 e[closed]/0 fd 8/8/-1 sock 8 cc -1)
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65230 to ::1 port 8888 (t4 r46 i0/0 o0/20 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug3: send packet: type 1
debug1: channel 0: free: port listener, nchannels 3
debug3: channel 0: status: The following connections are open:
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65230 to ::1 port 8888 (t4 r46 i0/0 o0/0 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug1: channel 1: free: port listener, nchannels 2
debug3: channel 1: status: The following connections are open:
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65230 to ::1 port 8888 (t4 r46 i0/0 o0/0 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug1: channel 3: free: direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65230 to ::1 port 8888, nchannels 1
debug3: channel 3: status: The following connections are open:
#3 direct-tcpip: listening port 8888 for localhost port 8888, connect from ::1 port 65230 to ::1 port 8888 (t4 r46 i0/0 o0/0 e[closed]/0 fd 9/9/-1 sock 9 cc -1)
debug3: fd 1 is not O_NONBLOCK
Transferred: sent 7360, received 1984 bytes, in 57.1 seconds
Bytes per second: sent 128.8, received 34.7
【问题讨论】:
-
你怎么知道隧道建好了,又怎么知道它不起作用?使用
-vv查看ssh的详细输出。此外,您是否检查过 Jupyter 是否正在运行并接受 DestHost 上的连接,例如ssh DestAlias curl http://localhost:8888? -
ssh DestAlias curl http://localhost:8888有效,远程 jupyter 显示302 GET /,-vv似乎成功验证了 DestHost。但是,当我尝试在 chrome 中打开 jupyter 时,日志的前几行显示:debug1: channel 2: new [direct-tcpip]\n debug2: channel 3: read<=0 rfd 9 len 0\n debug2: channel 3: read failed\n debug2: channel 3: chan_shutdown_read (i0 o0 sock 9 wfd 9 efd -1 [closed])。是不是因为 JumpHost 做了一些事情,比如它阻止了读取? -
尝试将整个日志附加到您的问题中。
-
在这里,我更改了一些敏感信息,如果有任何遗漏请告诉我
标签: ssh portforwarding ssh-tunnel