Parami中等效的“ssh”代理命令

2024-10-01 00:34:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试所有可能的方法连接到SFTP服务器--

对于此代码

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
mykey = paramiko.RSAKey.from_private_key_file("/Users/roth/.ssh/id_rsa", password="XXXX")

我明白了

paramiko.ssh_exception.SSHException: Could not deserialize key data.

如果我这样做

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname="128.xx.xx.xx", username="roth", passphrase="roth", password="XXXX", key_filename="/Users/roth/.ssh/id_rsa")

我明白了

paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 128.xx.xx.xx

我不知道为什么,因为我可以使用终端连接到SFTP,或者使用密钥+密码短语,或者只使用密码:

ssh -vvv 

OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /Users/roth/.ssh/config
debug1: /Users/roth/.ssh/config line 1: Applying options for *
debug1: /Users/roth/.ssh/config line 8: Applying options for 128.30.*
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Executing proxy command: exec ssh -W 128.xx.xx.xx:22 jump.xxx.xxx.edu
debug1: permanently_drop_suid: 501
debug1: identity file /Users/roth/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/roth/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5

Tags: keynoidparamikotypeloadpublicusers
1条回答
网友
1楼 · 发布于 2024-10-01 00:34:29

Executing proxy command: exec ssh -W 128.xx.xx.xx:22 jump.xxx.xxx.edu

您的ssh使用跳转代理服务器(aka SSH tunnel)进行连接。你知道吗

要在JSch中实现跳转服务器,请参见official ^{} example。你知道吗


顺便说一句,在最新版本的OpenSSH中,通过跳转服务器连接有比使用“代理命令”更好的方法。见How can I download a file from a host I can only SSH to through another host?

相关问题 更多 >