-1

I'm new at python and i'm trying to create a Python script to SSH (Throw putty), to my server and to execute 'sudo reboot' command (as you probbebly know , sudo is a requied a pass).

as I search here and google, I found this: Python script for SSH through PuTTY

At Putty download page there is 'Plink' I've downloaded that (few version tbh) and it's just open it and close it , not installing something or showme anything. just closing the window soon it's opened. What am I missing? also tried to do that with Paramiko:

import paramiko

host = "myip"
port = 22
username = "myusername"
password = "mypassword"

command = "sudo reboot"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)

stdin, stdout, stderr = ssh.exec_command(command)
ssh.close()

Thank you.

8
  • why use putty? use paramiko - docs.paramiko.org/en/stable/api/client.html Commented Sep 26, 2021 at 13:42
  • I've tried that as well, with that: kite.com/python/answers/how-to-ssh-using-paramiko-in-python i've installed it and it's not really working and I don't know how to add a command to execute. Commented Sep 26, 2021 at 13:45
  • 1
    No one will be able to help if you are not sharing the code. So share the code that calls paramiko. Commented Sep 26, 2021 at 13:47
  • I've editted the thread, thank you. Commented Sep 26, 2021 at 13:54
  • 1
    what happen when you run the code? Please attache all error details (if there is one) Commented Sep 26, 2021 at 13:56

1 Answer 1

0

If you have problems with executing commands, you need to read their (error) output to see any error messages.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.