I just installed a fresh ubuntu server 12.04. I log in over SSH and use sudo -s
to get root access. Then I use shutdown now
and the server closes the connection. I cannot access the server over SSH, FTP or HTTP anymore, it appears to be off. But it isn't. The server stays on, without being useful. Why? How can I shutdown the server with SSH?
Asked
Active
Viewed 1e+01k times
18
1 Answers
31
You can try this command over SSH:
sudo poweroff
If you want to just send this command over SSH and authenticate in one go, append the command to the regular SSH command:
ssh -t <options> <user>@<hostname> sudo poweroff
Thanks muru for suggesting the -t
option to allow for entering the sudo password.
-
2Also you can specify password: ssh user@host 'echo password | sudo -S poweroff' – dds Feb 04 '13 at 11:10
-
3It's generally not a good idea to specify passwords in commands like that (plain text). I've removed the SSH part from your question as the
poweroff
part is what it is about (and a good suggestion). Removed my earlier comment crititizing that now. +1 – gertvdijk Feb 04 '13 at 11:16 -
@gertvdijk - If I do not put the password in the ssh command, how can I shut down the machine in just one line of command? – Casper Mar 11 '17 at 19:06
-
-
2@gertvdijk If
sudo
wants to ask for a password, perhaps-t
would be needed (or an askpass program) – muru Mar 12 '17 at 09:47 -
I suggest ssh root@ip halt which is similar to
-t
if you are allowed to login as root. Why does'halt'
with quotation marks not work? I pass a string which is a cmd to ssh. Maybe it is interpreted asstring
. – Timo Aug 03 '21 at 20:01
-h
flag toshutdown
like this?shutdown -h now
– gertvdijk Feb 04 '13 at 10:36shutdown -h now
works (as doespoweroff
, mentioned in the first answer) – Feb 05 '13 at 09:30