|
各位大神好,我是初学者,学习的版本是Python3.5,用的IDE是pycharm
现在用django的paramiko远程连接其他Linux主机,并执行命令,通过用户名和密码验证的形式可以登陆远程主机并执行命令
我现在为了不显示密码,想通过rsa秘钥的形式来请求远程主机的shell命令,代码如下:
def pw(request):
host_ip='192.168.30.251'
host_port=22
username='root'
pkey_path="E:\\zc_test\\id_rsa"
key = paramiko.RSAKey.from_private_key_file(pkey_path)
s=paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname=host_ip,username=username, port=host_port, pkey=key)
stdin, stdout, stderr=ssh.exec_command('df -h')
print(stdout.read().decode())
return HttpResponse('OK')
这样写的输出始终是下图:
paramiko.ssh_exception.AuthenticationException: Authentication failed.
正常情况应该要输出df -h的结果
id_rsa我是从192.168.30.251上通过FTP的形式下载到我Windows机器上的E:\zc_test目录,Python是运行在我Windows机器上,请教各位大佬,这是什么问题导致的?谢谢
|
|