1

On machine A I want to have a small python script to execute a command on machine B. Machine A is Windows with freesshd running on it, and machine B can be either Windows or Linux. I only have a username and a password to log in to machine B, no other way of authentication.

How can I create a python script to run a command on machine B? ssh would be fine, but where to find that command on Windows? And it has to be done without paramiko, since this module does not wok for unknown reasons.

Alex
  • 41,580
  • 88
  • 260
  • 469
  • Found similar question that actually installs paramico on windows http://stackoverflow.com/questions/24514571/difficult-to-install-python-ssh-library-on-windows-ssh-has-been-replaced-with – Karl Nov 27 '14 at 13:09

2 Answers2

0

I haven't tried this on Windows but to handle input and output of a command pexpect is a good candidate. It also has a ssh part http://pexpect.readthedocs.org/en/latest/api/pxssh.html.

Did some more digging. There is a windows port of pexpect: https://gist.github.com/anthonyeden/8488763

Use that along with putty on the command line in windows.

Example of Putty on command line: http://etherealmind.com/putty-command-line/

Karl
  • 170
  • 9
0

If you can't get paramiko working, just do it manually with Popen: http://python-for-system-administrators.readthedocs.org/en/latest/ssh.html

Gillespie
  • 5,780
  • 3
  • 32
  • 54
  • @JohnPrawyn You'd need a cygwin-esque environment if you want to invoke `ssh` from the commandline or with `popen`. Otherwise you need a library like `paramiko` or `pyssh`. – Gillespie Aug 26 '16 at 17:46