尽管设置了 key_filename

问题描述

我正在使用 fabfile 进行 django 部署。我正在通过 bastin 主机连接到我的部署服务器(使用 fabfile 中的 env.gateway 选项,env.gateway=bastin_IP),然后运行所需的命令。

Following options are set in fabfile,added for reference.
env.gateway = 'user@xx.xx.xx.1' #bastin_IP
env.key_filename = ['path/to/pem/file']
env.user = 'user'
env.port = 22

现在每当我运行命令时,它总是提示输入用户密码,消息显示如下。 [xx.xx.xx.002] 'user' 的登录密码:

注意:这里显示在消息之前的 IP 是我的部署/生产服务器的 IP。

我假设(在看到上面的消息后)是与 bastin 成功建立连接,但它没有与部署/生产服务器连接。尽管每当我尝试通过 putty(在 Windows 上)连接时,我都可以登录到 bastin 主机(使用 openssh 私钥),然后从 bastin 登录到任何其他部署/生产服务器,而无需密码。

请告诉我,实际问题是什么以及如何解决。我做错了什么?

更新: 我添加了以下代码来检查 paramiko 的调试信息:

import paramiko,os
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)

调试日志在这里,它可能有助于更好地理解,出了什么问题:

DEBUG:paramiko.transport:starting thread (client mode): 0x8945a208
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_7.4
INFO:paramiko.transport:Connected (version 2.0,client OpenSSH_7.4)
DEBUG:paramiko.transport:kex algos:['curve25519-sha256','curve25519-sha256@libssh.org','ecdh-sha2-nistp256','ecdh-sha2-nistp384','ecdh-sha2-nistp521','diffie-hellman-group-exchang
e-sha256','diffie-hellman-group16-sha512','diffie-hellman-group18-sha512','diffie-hellman-group-exchange-sha1','diffie-hellman-group14-sha256','diffie-hellman-group14-sha1','diff
ie-hellman-group1-sha1'] server key:['ssh-rsa','rsa-sha2-512','rsa-sha2-256','ecdsa-sha2-nistp256','ssh-ed25519'] client encrypt:['chacha20-poly1305@openssh.com','aes128-ctr','ae
s192-ctr','aes256-ctr','aes128-gcm@openssh.com','aes256-gcm@openssh.com','aes128-cbc','aes192-cbc','aes256-cbc','blowfish-cbc','cast128-cbc','3des-cbc'] server encrypt:['chach
a20-poly1305@openssh.com','aes192-ctr','cast
128-cbc','3des-cbc'] client mac:['umac-64-etm@openssh.com','umac-128-etm@openssh.com','hmac-sha2-256-etm@openssh.com','hmac-sha2-512-etm@openssh.com','hmac-sha1-etm@openssh.com','umac-64@openssh.com','umac-128@openssh.com','hmac-sha2-256','hmac-sha2-512','hmac-sha1'] server mac:['umac-64-etm@openssh.com','hmac-sha2-256-etm@open
ssh.com','hmac-sha1'] client compress:['
none','zlib@openssh.com'] server compress:['none','zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: XXXX
DEBUG:paramiko.transport:HostKey agreed: XXXX
DEBUG:paramiko.transport:Cipher agreed: XXXX
DEBUG:paramiko.transport:MAC agreed: XXXX
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Trying discovered key b'6303...XXXX..5f' in E://key.pem
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:Received global request "hostkeys-00@openssh.com"
DEBUG:paramiko.transport:Rejecting "hostkeys-00@openssh.com" global request from server.
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:starting thread (client mode): 0x8943d780
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.7.2
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_7.4
INFO:paramiko.transport:Connected (version 2.0,client OpenSSH_7.4)
DEBUG:paramiko.transport:kex algos: XXXXXXXXXXXXXXXXXXXX client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: XXXX
DEBUG:paramiko.transport:HostKey agreed: XXXX
DEBUG:paramiko.transport:Cipher agreed: XXXX
DEBUG:paramiko.transport:MAC agreed: XXXX
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-ed25519 host key for XX.XX.XX.X: b'7bdd....XXXX....026c2e'
DEBUG:paramiko.transport:Trying discovered key b'6303....XXXX....39bf5f' in E://key.pem
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) Failed.
[XX.XX.XX.X] Login password for 'user':

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)