Easy way to shut down Ubuntu remotely

SSH is a good way to shut the remote machine down. Since this is on your local WiFi you could also think of installing VNC. This will give you full remote control of the machine. Similar to Teamviewer but more efficient.
 
Don't use passwords. Add public key to authorized_keys file. No good to have a shutdown script that requires the user's attention.
 
Don't use passwords. Add public key to authorized_keys file. No good to have a shutdown script that requires the user's attention.

Doesn't the actual shutdown command require you to enter a password? I honestly can't remember, just wondering.
 
I have created 3 different users, with the most simple of passwords.

maakoopasb

maakoop1

Etc

No luck.

There is more info on the thread about the home Server of mine don't want to hijack ockies thread.

When you are logged into any of those users run "groups" from terminal.

Odds are they don't have ssh access enabled.
 
Doesn't the actual shutdown command require you to enter a password? I honestly can't remember, just wondering.

Nope. You can just run this:

Code:
ssh root@machine "shutdown -h now"

If you have key access it shuts down immediately.

Also good idea to add a shorter time-out so the command doesn't wait too long if the system is not responding.

Code:
ssh -o ConnectTimeout=10 root@machine "shutdown -h now"


This example uses root, but sudo works fine for non-root users:

Code:
ssh -o ConnectTimeout=10 user@machine "sudo shutdown -h now"

I use this in my UPS shutdown scripts.
 

my guess is you are not hitting the server you think you are trying to access. Maybe a NAT issue and you are actually trying to log into a router?

Typically this will happen when you configure dynamic dns without port forwarding or you try to access the server from inside your home network using the wan ip.
 
my guess is you are not hitting the server you think you are trying to access. Maybe a NAT issue and you are actually trying to log into a router?

Typically this will happen when you configure dynamic dns without port forwarding or you try to access the server from inside your home network using the wan ip.

All of that sounds pretty damn possible because non of freedns's clients actually work and I'm not sure that Zyxell VDSL router of mine is forwarding the ports correctly.

I actually have 0 idea what I am doing I just want to learn linux, but compared to windows the documentation is not friendly
 
Nope. You can just run this:

Code:
ssh root@machine "shutdown -h now"

If you have key access it shuts down immediately.

Also good idea to add a shorter time-out so the command doesn't wait too long if the system is not responding.

Code:
ssh -o ConnectTimeout=10 root@machine "shutdown -h now"


This example uses root, but sudo works fine for non-root users:

Code:
ssh -o ConnectTimeout=10 user@machine "sudo shutdown -h now"

Yes but you are root already which you would have elevated at some time earlier.

I'm sure as non root you'll need to give a password.

****

Unless of course you are using keys for direct root access...in which case there are a lot of other things I would be more worried about.
 
Last edited:
why leave sshd listening on port 22 and inviting allsorts to try and hack it?

move it to a nonstandard port (222 or 2222)...
 
Top
Sign up to the MyBroadband newsletter
X