Passwordless SSH using paramiko

吃可爱长大的小学妹 提交于 2021-02-09 00:46:04

问题


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.

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

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.

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

This is my code:

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") 

回答1:


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

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.



来源:https://stackoverflow.com/questions/48112246/passwordless-ssh-using-paramiko

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!