Reputation: 2079
I am trying to use Python paramiko to execute commands on a remote server. When I run the following commands I get the prompt back and it appears to have succeeded as I get the prompt back
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('a.b.c.d', username='server', password='xyz')
>>>
The only response I get when I try to execute a command is []
>>> stdin, stdout, stderr = ssh.exec_command("host")
>>> stdout.readlines()
[]
Almost any command gives this same output. The command "host" when ssh is executed from the shell gives several lines of Usage output
I get this error if I don't give password
>>> ssh.connect('a.b.c.d', username='server')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\paramiko\client.py", line 307, in connect
File "build\bdist.win32\egg\paramiko\client.py", line 520, in _auth
paramiko.ssh_exception.SSHException: No authentication methods available
I don't know if the SSH connection is through and why commands are not being executed.
Should something be added for authentication? Am I missing something?
Upvotes: 1
Views: 2390
Reputation: 2257
The reason you get no output in stdout, is because running "host" with no options (as you said) provides the usage. If you type "echo $?" immediately afterward, you'll see a "1" instead of a zero. This is the indicator that the usage actually writes to stderr, not stdout.
Try executing a command that will always return output to stdout, like "ls -l". This should resolve your issue.
Edit: Or print the contents of stderr, that should work too, although it's not terribly useful. I forgot to mention -- I know this is an old thread, but someone might still have this problem in the future.
Upvotes: 1