python - "ssh"Paramiko 中的等效代理命令

标签 python ssh sftp paramiko openssh

我正在尝试所有可能的方法来连接到 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

我不知道为什么,因为我可以通过使用 key + 密码或仅密码使用终端连接到 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

最佳答案

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

您的 ssh 使用跳转代理服务器(又名 SSH 隧道)进行连接。

要在 JSch 中实现跳转服务器,请参阅 official JumpHosts.java example .


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

关于python - "ssh"Paramiko 中的等效代理命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59503547/

相关文章:

SSH IdentitiesOnly=yes 转发我所有的 key

python - Paramiko 的 SSHClient 和 SFTP

java - 3 : Permission denied. 在 com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)

python - 过滤 Tensorflow 数据集中的 NaN 值

python - Unicode 文件名到 python subprocess.call()

python - 使用 Paramiko 进行端口转发

r - devtools::install_git 通过 SSH

sftp - 如何使用 sftp 复制文件夹?

python - Nltk Sklearn 一元语法 + 二元语法

android - 上传图像时在google vm中调用python脚本