The question is simple.
What would be the script I would have to use to shut down a computer in my network thru ssh.
Normaly i would go to command line and:
ssh desktop
delik@desktop's password:
delik@desktop:~$ sudo shutdown -P 0
To power on I created a file and wrote:
wakeonlan xx:xx:xx:xx:xx:xx
And gave it the executable bit
That way to power on it requires only a double click. Would i be capable of doing the same to shutdown?
Best Answer
Assuming that the user you are going to use in remote.host is the same you use in local.host
In order to do that you have to first authorize your local.host to connect to you remote.host with no password.
To do that you have to: (as described here)
Step 1: Install ssh
Step 2: Create public and private keys using ssh-key-gen on local-host
On your local host, enter this command:
You should save the generated key in:
Press enter twice to leave the passphrase empty.
Step 3: Copy the public key to remote-host using ssh-copy-id
Note: ssh-copy-id appends the keys to the remote-host’s /home/yourusername/.ssh/authorized_key
Step 4: Login to remote-host without entering the password
Access to remote-host with no password. Success!
Now you have to be able to execute the sudo shutdown -P 0 with no password.
Modify /etc/sudoers on remote.host with visudo
That way user "yourusername" can execute the shutdown command with no password asked.
Login to the remote host.
Run:
By running visudo, it leads to edit /etc/sudoers.
Adding the line below to that file.
Done that, get back to your local.host
Create a new empty file and paste this line, modifying the remote.host's name
Save and close it, go to it's Properties slide to Permissions, and tic the execute this file as a program
Script Done!