找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2390|回复: 0

Windows通过django的paramiko远程Linux服务器失败

2

主题

2

帖子

2

积分

贫民

积分
2
cliffname 发表于 2018-4-4 17:46:20 | 显示全部楼层 |阅读模式
各位大神好,我是初学者,学习的版本是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机器上,请教各位大佬,这是什么问题导致的?谢谢




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表