6

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") 
Raaj
  • 1,180
  • 4
  • 18
  • 36

1 Answers1

5

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.

Raaj
  • 1,180
  • 4
  • 18
  • 36
  • Does your code really work? You did not answer your question *Where's the ssh obj passed?*. –  Jan 06 '18 at 06:26