且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 SSH 密钥通过 Paramiko 连接到 SFTP - Pageant

更新时间:2023-12-05 13:21:10

当使用 RSAKey.from_private_key_file.

但请注意,在使用 Pageant 时,您不必完全加载密钥.这就是使用身份验证代理的意义所在.但只有 SSHClient 支持盛会.Transport 类本身没有.

Though note that you do not have to load the key at all, when using the Pageant. That's the point of using an authentication agent. But only the SSHClient class supports the Pageant. The Transport class does not, on its own.

您可以按照如何在 Windows 上通过 Paramiko 使用 Pageant 中的代码?
尽管 allow_agent 默认为 True,但实际上代码没有什么特别的.

You can follow the code in How to use Pageant with Paramiko on Windows?
Though as the allow_agent is True by default, there is actually nothing special about the code.

一旦连接并通过身份验证,请使用 SSHClient.open_sftp 方法 获取SFTPClient 的实例.

Once connected and authenticated, use the SSHClient.open_sftp method to get your instance of the SFTPClient.

ssh = paramiko.SSHClient()
ssh.connect(host, username='user', allow_agent=True)
sftp = ssh.open_sftp()

您还需要验证主机密钥:
Paramiko未知服务器"

You will also need to verify the host key:
Paramiko "Unknown Server"