Shut down computer using ssh

5

What ways are there to shut down a computer using ssh? I'm running on linux and when I try to shut it down remotely using ssh, it doesn't actually work. I used the command sudo shutdown now. Afterwards, it said that the system is going down for maintenance NOW or whatever. However, when I got home, I came to discover that the computer was still on stuck on the Plymouth shut-down screen.

How can I achieve this?

KalSae

Posted 2015-04-28T22:02:03.470

Reputation: 57

6Have you tried: su, enter password, shutdown -h now? – LPChip – 2015-04-28T22:14:08.030

5This doesn't sound like a linux problem. This sounds like a hardware problem that your machine refuses to shut down after receiving the shutdown command. What is Plymouth? – hymie – 2015-04-29T00:28:02.557

2What distribution and version of Linux are you using? What messages are showing on the Plymouth shutdown screen? Can you edit your question to post a screenshot? Have you looked at the log files (e.g., /var/log/messages)? Can you edit your question to include the relevant part of the log file from when you began the shutdown to when it got stuck? If you want a good diagnosis you should provide more information. – D.W. – 2015-04-29T01:32:35.220

Answers

17

Multiple ways, depending on habits and needs, but the most common method is:

shutdown -h now

Because it’s clean, it does a sync for all drives, and it’s easy to alter its behavior if you for some reason want to., For example, shut down an hour in the future instead.

In your particular case, it’s missing the -h flag, which requests a poweroff as well. Without the -h flag, it is left on the linux equivalent of the old Windows 95 “You can now shut off your computer” or whatever it was that it used to say.

Jarmund

Posted 2015-04-28T22:02:03.470

Reputation: 5 155

1This might depend on the platform. At least on Fedora 21 (with systemd), --poweroff is the default, so shutdown now will shut down the machine even without the -h flag. I haven't checked any other distribution or version of Fedora. Have you checked what distros this applies to? – D.W. – 2015-04-29T01:34:45.297

@D.W. Most of the ones I use (centos, mint, arch), but I do remember FreeBSD 4.0 (yep, that long ago) being different, although I cannot remember how. – Jarmund – 2015-04-29T07:30:57.383

1This is the right solution! I have a Debian VM that I connect to, using xmin, and this is the command I use to shut it down. And it works all the time. – Ismael Miguel – 2015-04-29T08:31:01.900

1I usually use exec shutdown -h now just so the bash shell I am running it from gets to save its history before the shutdown command is run. – kasperd – 2015-04-29T17:18:05.620

For how the BSDs are different, including from one another, see http://unix.stackexchange.com/a/196471/5132 . For how the semantics of shutdown now have changed with systemd, see http://unix.stackexchange.com/a/196014/5132 .

– JdeBP – 2015-05-01T21:52:23.743

@JdeBP Way back before converting to linux I was a FreeBSD guy (this was around version 4.3 or thereabout), and I think the only thing I did differently was uppercase NOW: shutdown -h NOW. I may remember incorrectly, tho. – Jarmund – 2015-05-01T21:56:44.047

9

Try sudo shutdown -h now (the -h is for "halt")

Otherwise, see if something is hanging it up. Modem Manager and Network Manager are known to cause issues on some distros.

linuxdev2013

Posted 2015-04-28T22:02:03.470

Reputation: 1 051

7

Instead of shutdown try the poweroff command. This may not work on all distros though.

Gaurav Joseph

Posted 2015-04-28T22:02:03.470

Reputation: 1 503

5

Taken from: Shutting down a computer remotely

Shutdown doesn't turn off the computer unless you use the -P option e.g.

sudo shutdown -P now

Alternatively you can use sudo poweroff which does the same thing.

thilina R

Posted 2015-04-28T22:02:03.470

Reputation: 2 634

1This might depend on the platform. At least on Fedora 21 (with systemd), --poweroff is the default, so shutdown now will shut down the machine even without the -h flag. I haven't checked any other distribution or version of Fedora. Have you checked whether that answer is still valid on modern Linux distros? – D.W. – 2015-04-29T01:34:59.833

--poweroff is for unpriveldged useres I did assume (maybe prematurely) that it was a elevated ssh session (I also use Fedora --22 in my case) – linuxdev2013 – 2015-04-29T17:43:00.697

2

You have diferent ways:

By Run Level

init 0

with Shutdown command

shutdown [-option] time

example:

shutdown -h now

Another ways:

Poweroff <--- Reference

poweroff

Halt <--- Reference

halt

Francisco Tapia

Posted 2015-04-28T22:02:03.470

Reputation: 2 383

1

I normally use the init command to do that. If you want to shutdown it's this:

sudo init 0

Nobody has suggested this so far. Is there a disadvantage or reason not to use runlevels?

farosch

Posted 2015-04-28T22:02:03.470

Reputation: 355

2Well the systemd doco does say that "the concept of SysV runlevels is obsolete". ☺ The actual thing that people haven't addressed so far is not the commands to use, but why a shutdown would have got stuck on a plymouth screen. But the questioner hasn't even told us the operating system being used. – JdeBP – 2015-05-01T22:15:02.807