使用 paramiko 的无密码 SSH [英] Passwordless SSH using paramiko

查看:119
本文介绍了使用 paramiko 的无密码 SSH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我是 Paramiko 的菜鸟,试图从远程服务器上的 python 脚本(在个人机器上)运行一些命令.远程服务器不需要密码即可连接.

Issue : I'm a noob with Paramiko, trying to run some commands from a python script (on personal machine) on a remote server. The remote server doesn't need a password to connect to.

例如,如果我这样做root@[IPaddress] 在我的 Mac 上,我可以通过 MacbookPro 终端成功连接到远程服务器.

For example, if I do root@[IPaddress] on my Mac, I'm successfully able to connect to the remote server via MacbookPro terminal.

但是,我正在尝试使用 Paramiko 在 Python 脚本中执行此操作,无论我做什么,都会收到身份验证错误或无可用身份验证方法.

However, I'm trying to do this inside a Python script using Paramiko, and no matter what I do, I get an Authentication error or No Authentication methods available.

我经历了Paramiko AuthenticationException 问题,但在没有丰富经验的情况下,我的答案含糊不清与帕拉米科.帮助?

I went through Paramiko AuthenticationException issue but the answers there are vague for me to implement without significant experience with Paramiko. Help?

这是我的代码:

import paramiko
import os
from paramiko import SSHClient

#Borrowed from the linked post 
class SSHClient_noauth(SSHClient):
    def _auth(self, username, *args):
        self._transport.auth_none(username)
        return

#How do I implement? 
ssh =  SSHClient()
sshc = SSHClient_noauth()._auth(username="root") #Where's the ssh obj passed?
sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sshc.connect("10.xxx.xxx.xxx") 

推荐答案

好吧,不要让反对票让我失望.

Well, not to let the negative vote bog me down.

尝试了 sshc.connect(remoteIP, username=username, password="") 并且成功了.如果有人被困了一两个多小时试图让它工作,特别是工作,你可能想尝试输入"而不是 None.

Tried doing sshc.connect(remoteIP, username=username, password="") and it worked. In case someone has been stuck for over an hour or two trying to get this working, especially for work, you might want to try putting in a "" instead of None.

这篇关于使用 paramiko 的无密码 SSH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆