【问题标题】:Authentication failed pysftp with private key使用私钥的 pysftp 身份验证失败
【发布时间】:2022-01-25 01:25:16
【问题描述】:

使用 Pysftp 库 sftp 到服务器,我在尝试连接时收到身份验证失败。

但是在 filezilla 中使用相同的凭据我可以连接。

from pysftp import CnOpts, Connection
from paramiko import RSAKey
import io

private_key_text = '''
-----BEGIN OPENSSH PRIVATE KEY-----
   key removed...
-----END OPENSSH PRIVATE KEY-----
'''

    passphrase = 'my_passphrase'
    private_key = RSAKey.from_private_key(io.StringIO(private_key_text), password=passphrase)
    host = 'host_address'
    username = 'username'
    cnopts = CnOpts()
    target_dir = '/home'
    cnopts.hostkeys = None
    with Connection(host=host, username=username, private_key=private_key, private_key_pass=passphrase,
                    cnopts=cnopts, default_path=target_dir) as sftp:
        print(f'Successfully connected to remote SFTP server [{host}]')
    

【问题讨论】:

    标签: python ssh sftp


    【解决方案1】:

    Paramiko 最近在 2.9.x 中添加了一些导致paramiko.ssh_exception.AuthenticationException('Authentication failed.') 异常的代码。尝试显式安装paramiko==2.8.1,看看问题是否仍然存在。

    请参阅https://www.paramiko.org/changelog.htmlhttps://www.paramiko.org/changelog.html 的 2.9.0 更改日志说明

    还有这个问题:https://github.com/paramiko/paramiko/issues/1961

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-16
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 2012-10-27
    • 2021-05-19
    • 2018-11-02
    相关资源
    最近更新 更多