gpt4 book ai didi

python - SSH 帕里科 Azure

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:43 25 4
gpt4 key购买 nike

我在 python 中使用 paramiko(版本 paramiko==1.15.3)进行 ssh 通常没有问题。正在做:

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 终端使用 key 文件 ssh 进入 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.

最佳答案

/etc/ssh/sshd_config 中设置 LogLevel DEBUG 后,我检查了服务器上的日志 /var/log/auth.log >。事实证明,paramiko 正在尝试使用我本地的指纹 key ssh-agent (可以通过执行 `ssh-add -l 来列出),而不是实际尝试我在 ssh.connect 的参数中提供的 key 文件。通过终端的 Openssh 也尝试了来自 ssh-agent 的 key ,最后尝试了 key 文件。

我将 azure key 文件添加到 ssh-agent 中:

ssh-add /home/lee/.ssh/the-azure-ssh.key

并再次运行上面的脚本。这次paramiko成功建立了连接。

(有谁知道为什么将 key 添加到代理可以与 paramiko 配合使用,但不能单独使用 key 文件?)

关于python - SSH 帕里科 Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33271600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com