-1

I have absolutely basic knowledge regarding networking. And I know about ssh tunneling or connections but I have no clue how to apply it or use it. I'm designing an application for security and I need help getting past this hurdle.

Somil Sharma
  • 61
  • 1
  • 7

3 Answers3

1

You can create a user on the server you need to shutdown, that has rights to perform the action. Then add a key-pair, so your client can access this account without a password to perform the actual shutdown.

Now you can shutdown over ssh. The basic method to do this, is:

ssh -t <options> <user>@<hostname> sudo poweroff

(via)

It looks like you want to do this in a python program, so now you need to call this via python. A simple way is this

   commands.getstatusoutput("ssh machine 1 'your script'")

(via note, there are more options in that question, and more questions about it to be found)

Community
  • 1
  • 1
Nanne
  • 64,065
  • 16
  • 119
  • 163
1

I composed a command to suspend or shutdown a remote host over ssh. This may be used to suspend / shutdown a remote computer without an interactive session and yet not keep a terminal busy. You will need to give permissions to the remote user to shutdown / suspend using sudo without a password. Additionally, the local and remote machines should be set up to SSH without an interactive login. The script is more useful for suspending the machine as a suspended machine will not disconnect the terminal.

local_user@hostname:~$ ssh remote_user@remote_host "screen -d -m sudo pm-suspend"

source: कार्यशाला (Kāryaśālā)

Lord Loh.
  • 2,437
  • 7
  • 39
  • 64
0

Create a tcp server on one machine and tcp client on another machine.

Send the string "shutdown" from the client to the server.

Write the tcp server in such a way that it shuts down the machine when it gets the string "shutdown".

thewhitetulip
  • 3,235
  • 3
  • 21
  • 26