18

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?

  • 1
    Possible dulpicate of http://askubuntu.com/questions/205674/remote-reboot-over-ssh-does-not-restart?rq=1 – Kevin Bowen Feb 04 '13 at 09:51
  • no, rebooting does work –  Feb 04 '13 at 10:05
  • 1
    I don't think this issue has anything to do with SSH. It just seems stuck in the shutdown procedure somewhere, or, the ACPI command isn't perfoming an actual power off (just a halt). Do you have physical access to a console of that server to clarify? (or remote-KVM, serial console, etc.) Oh, and have you tried adding the -h flag to shutdown like this? shutdown -h now – gertvdijk Feb 04 '13 at 10:36
  • It shouldn't be stuck, it's a clean installation with only LAMP installed. shutdown -h now works (as does poweroff, mentioned in the first answer) –  Feb 05 '13 at 09:30

1 Answers1

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.

gertvdijk
  • 67,947
dds
  • 639
  • 2
    Also you can specify password: ssh user@host 'echo password | sudo -S poweroff' – dds Feb 04 '13 at 11:10
  • 3
    It'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
  • @Casper Added :) – gertvdijk Mar 12 '17 at 09:24
  • 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 as string. – Timo Aug 03 '21 at 20:01