mydigi
mydigi

Reputation: 11

authentication exception in paramiko

I am trying to ssh to a device using paramiko and run some commands using the following code in a virtual environment

import paramiko from getpass import getpass

if name == "main":

hostname = raw_input("Please enter your IP address: ")
username = raw_input("Please enter your username: ")
password = getpass()

s = paramiko.SSHClient()


s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.load_system_host_keys()
s.connect(hostname= hostname, username= username, password= password)
print s  
s.command = 'dir'
(stdin, stdout, stderr) = s.exec_command(command)
for line in stdout.readlines():
    print line 
s.close()

when i try running the above code i get the following error:

File "param.py", line 14, in s.connect(hostname= hostname, username= username, password= password) File "/users/myuser/myvirtualenv/lib/python2.7/site-packages/paramiko/client.py", line 394, in connect look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host) File "/users/myuser/myvirtualenv/lib/python2.7/site-packages/paramiko/client.py", line 649, in _auth raise saved_exception paramiko.ssh_exception.AuthenticationException: Authentication failed.

I can ssh to the device normally using putty. But when i try to do it in python using paramiko, I am getting authentication exception ..i dont really know why.

Upvotes: 1

Views: 9222

Answers (1)

halt_andcatchfire
halt_andcatchfire

Reputation: 21

I'm getting something similar with valid user/password input (as in, I can connect normally over sftp). It works for me when running s.connect(hostname= hostname, username= username, password= password, look_for_keys=False), but obviously it would be ideal if it would authenticate with both a password and an ssh key.

Upvotes: 2

Related Questions