How to: Shutdown or Restart an Ubuntu Server via SSH
How to: Shutdown or Restart an Ubuntu Server via SSH
If you want to remotely restart or shutdown an Ubuntu Server when connected via SSH you simply need to know the following commands (and use them of course):
sudo shutdown
and
sudo reboot
As always the accompanying man pages are a great resource:
Man Shutdown:
shutdown(8) System Manager’s Manual shutdown(8)
NAME
shutdown – bring the system downSYNOPSIS
shutdown [OPTION]… TIME [MESSAGE]DESCRIPTION
shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented.TIME may have different formats, the most common is simply the word ‘now’ which will bring the system down immediately. Other valid formats are +m, where m is the number of minutes to wait until shutting down and hh:mm
which specifies the time on the 24hr clock.If no option is specified, the default action is to bring the system down into single-user mode.
Once TIME has elapsed, shutdown sends a request to the init(8) daemon to bring the system down into the appropriate runlevel.
This is performed by emitting the runlevel(7) event, which includes the new runlevel in the RUNLEVEL environment variable as well as the previous runlevel (obtained from the environment or from /var/run/utmp) in the PRE‐
VLEVEL variable. An additional INIT_HALT variable may be set, this will contain the value HALT when bringing the system down for halt and POWEROFF when bringing the system down for power off.OPTIONS
-r Requests that the system be rebooted after it has been brought down.-h Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system.
-H Requests that the system be halted after it has been brought down.
-P Requests that the system be powered off after it has been brought down.
-c Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.
-k Only send out the warning messages and disable logins, do not actually bring the system down.
ENVIRONMENT
RUNLEVEL
shutdown will read the current runlevel from this environment variable if set in preference to reading from /var/run/utmpFILES
/var/run/utmp
Where the current runlevel will be read from; this file will also be updated with the new runlevel./var/log/wtmp
A new runlevel record will be appended to this file for the new runlevel.NOTES
The Upstart init(8) daemon does not keep track of runlevels itself, instead they are implemented entirely by its userspace tools.See runlevel(7) for more details.
AUTHOR
Written by Scott James Remnant <scott@netsplit.com>REPORTING BUGS
Report bugs at <https://launchpad.net/upstart/+bugs>COPYRIGHT
Copyright © 2009 Canonical Ltd.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.SEE ALSO
runlevel(7) init(8) telinit(8) reboot(8)
Upstart 2009-07-09 shutdown(8)
Man Reboot:
reboot(8) System Manager’s Manual reboot(8)
NAME
reboot, halt, poweroff – reboot or stop the systemSYNOPSIS
reboot [OPTION]… [REBOOTCOMMAND]halt [OPTION]…
poweroff [OPTION]…
DESCRIPTION
These programs allow a system administrator to reboot, halt or poweroff the system.When called with –force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself (with REBOOTCOMMAND argument passed) and directly reboots the system. Otherwise this simply invokes the shutdown(8)
tool with the appropriate arguments without passing REBOOTCOMMAND argument.Before invoking reboot(2), a shutdown time record is first written to /var/log/wtmp
OPTIONS
-f, –force
Does not invoke shutdown(8) and instead performs the actual action you would expect from the name.-p, –poweroff
Instructs the halt command to instead behave as poweroff.-w, –wtmp-only
Does not call shutdown(8) or the reboot(2) system call and instead only writes the shutdown record to /var/log/wtmp–verbose
Outputs slightly more verbose messages when rebooting, useful for debugging problems with shutdown.ENVIRONMENT
RUNLEVEL
reboot will read the current runlevel from this environment variable if set in preference to reading from /var/run/utmpFILES
/var/run/utmp
Where the current runlevel will be read from; this file will also be updated with the runlevel record being replaced by a shutdown time record./var/log/wtmp
A new runlevel record for the shutdown time will be appended to this file.AUTHOR
Written by Scott James Remnant <scott@netsplit.com>REPORTING BUGS
Report bugs at <https://launchpad.net/upstart/+bugs>COPYRIGHT
Copyright © 2009 Canonical Ltd.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.SEE ALSO
shutdown(8) telinit(8) runlevel(8)Upstart 2009-07-09 reboot(8)
Love
Can we use Let's Encrypt, the free and open certificate authority?
Hola! gracias por la info, me sirvió el comando sacandole el nombre del server. En mi caso, fue una migración…
Yes 3rd option helped me too. I removed the WC key Values from config file then started working.
I know this is from 2014. But really, thank you!