【发布时间】:2015-10-22 00:40:52
【问题描述】:
我通常在 python 中使用 paramiko(版本 paramiko==1.15.3)进行 ssh'ing 没有问题。正在做:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('mylinodebox.com', key_filename='key_filename='/home/me/.ssh/id_rsa_linode', port=2222)
stdin, stdout, stderr = ssh.exec_command('ls')
print stdout.readlines()
ssh.close()
这台 linode 机器对我来说非常好用。但是对于另一台 Azure 机器,如果我尝试同样的方法,只需将连接线替换为
ssh.connect('myazurebox.net', key_filename='/home/me/.ssh/the-azure-ssh.key', port=22)
我明白了
AuthenticationException: Authentication failed.
尽管事实上我从 linux 终端使用密钥文件 ssh'ing 到 Azure 机器没有任何问题(我做 ssh myazurebox 并且有下面的 ssh 配置),所以我知道信誉很好.
我的 ssh 配置文件看起来像
Host *
ForwardAgent yes
ServerAliveInterval 15
ServerAliveCountMax 3
PermitLocalCommand yes
ControlPath ~/.ssh/master-%r@%h:%p
ControlMaster auto
Host myazurebox
HostName myazurebox.net
IdentityFile ~/.ssh/the-azure-ssh.key
User <azureuser>
Host mylinodebox
HostName mylinodebox.com
IdentityFile ~/.ssh/id_rsa_linode
Port 2222
有谁知道为什么这不起作用?
在导入后添加paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) 行不会显示更多内容:
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEBUG:paramiko.transport:using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for myazurebox.net: 8d596885f13b8e45c1edd7d94bbfa817
DEBUG:paramiko.transport:Trying SSH agent key d403d1c6bec787e486548a3e0fbfa373
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) failed.
DEBUG:paramiko.transport:Trying SSH agent key 12e9db4c2cd2be32193s78b0b13cb5eb
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) failed.
DEBUG:paramiko.transport:Trying SSH agent key 1906e3debc819c0f5f40080d43de587d
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) failed.
【问题讨论】:
标签: python linux azure ssh paramiko