Python Forum
connect via ssh to a remote host and run a command locally - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: connect via ssh to a remote host and run a command locally (/thread-25945.html)



connect via ssh to a remote host and run a command locally - bartibog - Apr-16-2020

Hi everyone,

i'm new to python, please don't hold that against :-)

i'm looking to ssh into a remote computer and run a command locally, this is what i have so far but the local command doesn't seem to run.

if i run it without this command, i receive "Done."
stdin, stdout, stderr = client.exec_command("svt-shutdown-safe")

but when i run it with the above line, it get an error and the "svt-shutdown-safe" command doesn't run.

any help is much appreciated.

import paramiko

try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 

    client.connect("10.0.0.0", port="22", username="MyUsername", password="MyPassword")

    stdin, stdout, stderr = client.exec_command("svt-shutdown-safe")
    
finally:
    client.close()

print ("done.")