我正在尝试设置与Paramiko的跳转主机连接
这是我在~/.ssh/config
中的设置
Host jump.csail.mit.edu
GSSAPIAuthentication yes
GSSAPIKeyExchange yes
VerifyHostKeyDNS yes
Host *.csail.mit.edu !jump.csail.mit.edu 128.52.* 128.30.* 128.31.*
ProxyCommand ssh -W %h:%p jump.csail.mit.edu
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes
GSSAPIKeyExchange yes
如果我从终端连接,它就会工作
我还为Paramiko跳转主机连接找到了this code,我想知道基于上面的ssh配置设置应该设置jumpbox_public_addr
和jumpbox_private_addr
什么
import os
import paramiko
ssh_key_filename = os.getenv('HOME') + '/.ssh/id_rsa'
jumpbox_public_addr = '168.128.52.199'
jumpbox_private_addr = '10.0.5.10'
target_addr = '10.0.5.20'
jumpbox=paramiko.SSHClient()
jumpbox.set_missing_host_key_policy(paramiko.AutoAddPolicy())
jumpbox.connect(jumpbox_public_addr, username='root', key_filename=ssh_key_filename)
jumpbox_transport = jumpbox.get_transport()
src_addr = (jumpbox_private_addr, 22)
dest_addr = (target_addr, 22)
jumpbox_channel = jumpbox_transport.open_channel("direct-tcpip", dest_addr, src_addr)
target=paramiko.SSHClient()
target.set_missing_host_key_policy(paramiko.AutoAddPolicy())
target.connect(target_addr, username='root', key_filename=ssh_key_filename, sock=jumpbox_channel)
stdin, stdout, stderr = target.exec_command("ifconfig")
for line in stdout.read().split(b'\n'):
print(str(line))
target.close()
jumpbox.close()
谢谢大家!
jumpbox_public_addr
是跳转服务器的地址,应该是jump.csail.mit.edu
jumpbox_private_addr
(^{src_addr
参数是从jump.csail.mit.edu
到目标服务器的连接的源地址。一般来说,您并不关心这一点(因为您不关心大多数TCP连接的源地址和端口)。而且绝对不应该是22号端口。以下内容应告诉服务器使用默认值:相关问题 更多 >
编程相关推荐