linux中关机命令
虚拟主机问题之Linux关机与重启命令详解

虚拟主机问题之Linux关机与重启命令详解Linux下的关机与重启的命令有多种,每种方式略有些不同,除非有特别紧急的情况发生,否则不要通过直接关闭电源来关机,这可能会导致数据丢失。
1. shutdown:妥善的停机方式shutdown 是关机或重启系统最安全的方式。
shutdown可以在指定时间关机(定时关机),也可以让shutdown 在开始关闭系统之前等待一段时间,在等待过程中,shutdown 以越来越短的时间间隔发送一些消息给已登录的用户,警告用户,系统将要关闭,可以让用户在系统关闭之前做好相应的准备工作,防止发生数据丢失。
管理员也可以提供一个简短的说明,比如:更换设备,10:00恢复。
下面看一下shutdown的详细参数:shutdown [OPTION]… TIME [MESSAGE][-r] 重启计算器。
[-k] 并不真正关机﹐只是送警告信号给每位登录者[-h] 关机后关闭电源。
[-c] 取消目前正在执行的关机程序,可以给当前登录的用户一个提示信息[-F] 在重启系统时执行磁盘检查(fsck)[-f] 在重启系统时不检查磁盘比如要在10:00关闭系统,并给登录用户一条提示信息:$ shutdown -h 10:00 “系统维护10:00关机,11:00恢复”比如要在15分钟后重启计算机:$ shutdown -r +152. halt 更简单的关机方式halt命令执行关闭系统所需要的基本任。
它可以被shutdown -h调用,也可以单独使用。
halt 记录关机的情况,终止百必须的进程,执行sync系统调用,等待文件系统写操作完成,然后停止内核。
halt -n 不执行sync调用。
在fsck修复了根分区之后会用到这条命令。
如果fsck没用使用-n 选项,那么内核可能会用内存中组成上的超级块的老版本覆盖fsck的修改。
3. telinit 改变init的运行级别使用telnit可以指引init进入指定的运行级别。
linux物理服务器关机指令

linux物理服务器关机指令shutdown 命令shutdown 会给系统计划⼀个时间关机。
它可以被⽤于停⽌、关机、重启机器。
你可以指定⼀个时间字符串(通常是 now 或者⽤ hh:mm 指定⼩时/分钟)作为第⼀个参数。
额外地,你也可以设置⼀个⼴播信息在系统关闭前发送给所有已登录的⽤户。
重要:如果使⽤了时间参数,系统关机前 5 分钟,会创建 /run/nologin ⽂件。
以确保没有⼈可以再登录。
shutdown 命令⽰例:# shutdown# shutdown now# shutdown 13:20# shutdown -p now ### 关闭机器# shutdown -H now ### 停⽌机器# shutdown -r09:35 ### 在 09:35am 重启机器要取消即将进⾏的关机,只要输⼊下⾯的命令:# shutdown -chalt 命令halt 通知硬件来停⽌所有的 CPU 功能,但是仍然保持通电。
你可以⽤它使系统处于低层维护状态。
注意在有些情况会它会完全关闭系统。
下⾯是 halt 命令⽰例:# halt ### 停⽌机器# halt -p ### 关闭机器# halt --reboot ### 重启机器poweroff 命令poweroff 会发送⼀个 ACPI 信号来通知系统关机。
下⾯是 poweroff 命令⽰例:# poweroff ### 关闭机器# poweroff --halt ### 停⽌机器# poweroff --reboot ### 重启机器reboot 命令reboot 通知系统重启。
# reboot ### 重启机器# reboot --halt ### 停⽌机器# reboot -p ### 关闭机器。
电脑关机命令用法

电脑关机命令用法电脑关机命令用法指的是通过命令行或者脚本的方式来控制电脑的关机操作。
这种方式通常被用于自动化任务、远程操作或者系统管理等场景下。
在不同的操作系统下,电脑关机命令的用法可能会有所不同。
本文将分别介绍在Windows、Mac和Linux系统下的电脑关机命令用法,并且讨论一些相关注意事项。
一、Windows系统在Windows系统下,可以使用`shutdown`命令来控制电脑的关机操作。
`shutdown`命令的基本语法如下:```shutdown [/s][/r][/t xxx][/f][/p][/h][/hybrid][/e] [/?]````/s`选项表示关机,`/r`选项表示重启。
`/t`选项后面可以跟一个延迟时间,单位是秒,表示延迟多少秒后执行关机或重启操作。
`/f`选项表示强制关闭正在运行的应用程序。
`/p`选项表示关闭正在运行的应用程序而不提示用户。
`/h`选项表示休眠。
`/hybrid`选项表示休眠模式下使用快速启动。
`/e`选项表示启动高级启动选项菜单。
`/?`选项用于显示帮助信息。
要在10秒后关机,可以使用以下命令:```shutdown /s /t 10```二、Mac系统在Mac系统下,可以使用`sudo shutdown`命令来控制电脑的关机操作。
`sudo`命令用于获取管理员权限,因为关机操作需要管理员权限。
`shutdown`命令的基本语法如下:```sudo shutdown -h now````-h`选项表示关机,`now`表示立即执行操作。
如果想要延迟关机,可以将`now`替换成一个时间,例如`+10`表示10分钟后关机。
三、Linux系统在Linux系统下,可以使用`shutdown`命令来控制电脑的关机操作。
`shutdown`命令的基本语法如下:```shutdown [options] time [message]````options`可以是`-h`表示关机,`-r`表示重启。
Linux关机命令分析

Linux关机命令分析linux下有关关机重启的命令主要有:shutdown、reboot、halt、poweroff、telinit、init。
它们都可以达到关机或重启的目的,但是每个命令的工作流程并不一样。
它们都由软件包sysvinit生成,你可以从网上下载它的源码来分析各个命令的流程,同时,sysvinit也包含了与登陆等有关的命令。
下面分析sysvinit-2.86软件包的源码,同时参考它们的手册来对它们深入了解。
1、从Makefile可以知道,上面的命令并不都是互相独立的,poweroff、reboot是halt 的链接,telinit是init的链接。
ln -sf halt $(ROOT)/sbin/rebootln -sf halt $(ROOT)/sbin/poweroffln -sf init $(ROOT)/sbin/telinit在终端输入# ls -l /sbin/poweroff# ls -l /sbin/reboot# ls -l /sbin/telinit也可以看到上面的结果。
2、halt。
参数说明:[-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
[-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
[-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
[-f] 没有调用shutdown而强制关机或重启(halt/reboot)。
[-h] 使硬盘处于standby模式。
[-i] 关掉所有的网络接口。
[-p] 该选项为缺省选项。
就是关机时调用poweroff。
前面已经知道,poweroff、reboot是halt的链接,halt会首先判断用户执行的是否是poweroff和reboot中的一个。
如果执行的是poweroff,则等效于-p参数,执行reboot 的情况将在下面说明。
linux的shutdown命令详解

linux的shutdown命令详解linux下关机我们可以采用shutdown命令来实现,下面由店铺为大家搜集整理了linux的shutdown命令详解的相关知识,希望对大家有帮助!linux的shutdown命令详解命令简介:该命令可以安全关闭或者重新启动系统。
你没有看错,shutdown 命令不仅可以关闭系统、也可以重启Linux系统。
命令语法:/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]命令参数:参数长参数描叙-a Use /etc/shutdown.allow.-c中断关机:当执行"shutdown -h 12:00"指令时,只要按+键就可以中断关机的指令-f重新启动时不进行磁盘检测(fsck)-F重新启动时进行磁盘检测(fsck)-h关闭电源-k模拟关机(不是真的关机),只是向登录者发送警告信息出去!-n不调用init进程进行关机,而是强行关机-r关闭系统然后重新启动,类似于Windows平台restart-t延迟关机的时间-w仅做测试,并不真的将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件--help显示命令在线帮助linux的shutdown命令使用示例1: 查看reboot命令的帮助信息[root@db-server ~]# shutdown --helpshutdown: invalid option -- -Usage: shutdown [-akrhHPfnc] [-t secs] time [warning message]-a: use /etc/shutdown.allow-k: don't really shutdown, only warn.-r: reboot after shutdown.-h: halt after shutdown.-P: halt action is to turn off power.-H: halt action is to just halt.-f: do a 'fast' reboot (skip fsck).-F: Force fsck on reboot.-n: do not go through "init" but go down real fast.-c: cancel a running shutdown.-t secs: delay between warning and kill signal.** the "time" argument is mandatory! (try "now") **[root@db-server ~]#[root@db-server ~]# man shutdownSHUTDOWN(8) Linux System Administrator鈥檚Manual SHUTDOWN(8)NAMEshutdown - bring the system downSYNOPSIS/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]DESCRIPTIONshutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay.All processes are first notified that the system is going down by the signal SIGTERM. This gives programs likevi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc.shutdown does its job by signalling the init process, asking it to change the runlevel. Runlevel 0 is used tohalt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a statewhere administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shut-down. To see which actions are taken on halt or reboot see the appropriate entries for these runlevels in thefile /etc/inittab.OPTIONS-a Use /etc/shutdown.allow.-t sec Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, beforechanging to another runlevel.-k Don鈥檛really shutdown; only send the warning messages to everybody.-r Reboot after shutdown.-h Halt or poweroff after shutdown.-H Halt action is to halt or drop into boot monitor on systems that support it.-P Halt action is to turn off the power.-n [DEPRECATED] Don鈥檛call init(8) to do the shutdown but do it ourself. The use of this option is dis-couraged, and its results are not always what you鈥檇 expect.-f Skip fsck on reboot.-F Force fsck on reboot.-c Cancel an already running shutdown. With this option it is of course not possible to give the time argu-ment, but you can enter a explanatory message on the command line that will be sent to all users.time When to shutdown.warning-messageMessage to send to all users.The time argument can have different formats. First, it can be an absolute time in the format hh:mm, in whichhh is the hour (1 or 2 digits) and mm is the minute of the hour (in two digits). Second, it can be in the for-mat +m, in which m is the number of minutes to wait. The word now is an alias for +0.If shutdown is called with a delay, it creates the advisory file /etc/nologin which causes programs such aslogin(1) to not allow new user logins. Shutdown removes this file if it is stopped before it can signal init(i.e. it is cancelled or something goes wrong). It also removes it before calling init to change the runlevel.The -f flag means 鈥榬eboot fast鈥? This only creates an advisory file /fastboot which can be tested by the sys- tem when it comes up again. The boot rc file can test if this file is present, and decide not to run fsck(1)since the system has been shut down in the proper way. Afterthat, the boot process should remove /fastboot.The -F flag means 鈥榝orce fsck鈥? This only creates an advisory file /forcefsck which can be tested by the sys- tem when it comes up again. The boot rc file can test if this file is present, and decide to run fsck(1) witha special 鈥榝orce鈥?flag so that even properly unmounted filesystems get checked. After that, the boot process should remove /forcefsck.The -n flag causes shutdown not to call init, but to kill all running processes itself. shutdown will thenturn off quota, accounting, and swapping and unmount all filesystems.ACCESS CONTROLshutdown can be called from init(8) when the magic keys CTRL-ALT-DEL are pressed, by creating an appropriate entry in /etc/inittab. This means that everyone who has physical access to the console keyboard can shut the system down. T o prevent this, shutdown can check to see if an authorized user is logged in on one of the vir-tual consoles. If shutdown is called with the -a argument (add this to the invocation of shutdown in /etc/init-tab), it checks to see if the file /etc/shutdown.allow is present. It then compares the login names in thatfile with the list of people that are logged in on a virtual console (from /var/run/utmp). Only if one of thoseauthorized users or root is logged in, it will proceed. Otherwise it will write the messageshutdown: no authorized users logged into the (physical) system console. The format of /etc/shutdown.allow is one user name per line. Empty lines andcomment lines (prefixed by a #) are allowed. Currently there is a limit of 32 users in this file.Note that if /etc/shutdown.allow is not present, the -a argument is ignored.HALT OR POWEROFFThe -H option just sets the init environment variable INIT_HALT to HALT, and the -P option just sets that vari- able to POWEROFF. The shutdown script that calls halt(8) as the last thing in the shutdown sequence shouldcheck these environment variables and call halt(8) with the right options for these options to actually haveany effect. Debian 3.1 (sarge) supports this.FILES/fastboot/etc/inittab/etc/init.d/halt/etc/init.d/reboot/etc/shutdown.allowNOTESA lot of users forget to give the time argument and are then puzzled by the error message shutdown produces.The time argument is mandatory; in 90 percent of all cases this argument will be the word now.Init can only capture CTRL-ALT-DEL and start shutdown in console mode. If the system is running the X window System, the X server processes all key strokes. Some X11 environments make it possible to capture CTRL-ALT-DEL, but what exactly is done with that event depends on that environment.Shutdown wasn鈥檛designed to be run setuid./etc/shutdown.allow is not used to find out who is executing shut-down, it ONLY checks who is currently logged in on (one of the) console(s).AUTHORMiquelvanSmoorenburg,******************SEE ALSOfsck(8), init(8), halt(8), poweroff(8), reboot(8)November 12, 2003 SHUTDOWN(8)(END)2:马上关闭Linux系统,其中 now 相当于时间为 0 的状态[root@db-server ~]# shutdown -h nowBroadcast message from root (pts/1) (Sat Jan 10 18:51:34 2015):The system is going down for system halt NOW!3:系统2分钟后重新启动,其中+m表示几分钟后关机或开机。
Linux命令之shutdown

Linux命令之shutdown shutdown [选项] [时间] [通知消息](可以为空,但必须有参数和时间)系统关机命令,所有登录⽤户都可看到关机信息。
(1).常⽤选项-c 取消已经在进⾏的shutdown指令内容-h 关机-k 发送警告信息给所有登录者-r 重启(2).unbuntu独有参数,CentOS没有参数-f 重启后强制略过fsck磁盘检测-F 重启后强制进⾏fsck磁盘检测(3).实例特定时间执⾏关机命令shutdown –h now //⽴即关机shutdown –h 12:00 //在12:00关机指定五分钟后关机,并发出警告信息[root@CentOS6 桌⾯]#shutdown +5 “This System will be shutdown in 5 minutes”Broadcast message from root@CentOS6.8(/dev/pts/0) at 13:33 …The system is going down for maintenance in 5 minutes! //系统提醒This System will be shutdown in 5 minutes //⽤户⾃定义提醒指定3分钟后重启,并发出警告信息[root@CentOS6 桌⾯]#shutdown –r +3 “3分钟后关机重启”Broadcast message from root@CentOS6.8(/dev/pts/0) at 13:53 …The system is going down for reboot in 3 minutes! //系统提醒3分钟后关机重启 //⽤户⾃定义提醒给所有登录⽤户发送提醒[root@CentOS6 桌⾯]#shutdown –k “Waring:maybe the system will be shutdown”Shutdown:time expectedTry’shutdown --help’ for more information.[root@CentOS6 桌⾯]# shutdown –k 5 “Waring:maybe the system will be shutdown”[root@CentOS6 桌⾯]#Broadcast message from root@CentOS6.8(/dev/pts/0) at 14:26 …The system is going down for maintenance in 5 minutes!Waring:maybe the system will be shutdown。
Linux操作系统关机有技巧

Linux操作系统关机有技巧在Linux系统中,其关机命令就多达六种。
分别有shutdown、reboot、halt、poweroff、telinit、init 等命令。
虽然有些命令相互之间是父子的关系,但是至少可以说明Linux系统关在Linux系统中,其关机命令就多达六种。
分别有shutdown、reboot、halt、poweroff、telinit、init等命令。
虽然有些命令相互之间是父子的关系,但是至少可以说明Linux系统关机也有一番学问。
这些命令都可以达到关机或者重新启动系统的目的,但是他们每一个命令的工作流程都不一样,可以起到不同的目的。
笔者接下去要介绍的就是这些关机命令的特点以及在什么情况下应该采用什么命令。
一、这六个关机命令之间的关系。
在这六个命令中,有些命令之间是父子关系。
如halt与poweroff两个之间就是父子关系。
在halt命令中,如果加入-p参数的话,则其起到的作用就跟poweroff是相同的。
如果系统管理员要知道某个关机命令是否是其他关键命令的连接(即与其它关机命令是否有父子关系),可以利用下图所示的命令进行查询。
插图一:上面第一条记录,表示poweroff命令是halt命令的连接。
即poweroff命令是halt命令的子程序。
而第二条记录则表示halt命令不是其他命令的连接。
即halt关机命令是最顶级的命令。
所以系统管理员如果不了解这些关机命令的相互关系,则可以利用如上的命令进行查询。
以上这六个关机命令它们都是由软件包sysvinit产生,系统管理员可以从网上下载它的源码来分析各个命令的流程。
作为系统管理员,有必要了解这些命令的相同点以及差异,并根据自己的需要选择合适的关机命令。
而不是一味的采用poweroff命令来进行关机。
二、Halt关机命令解析。
Halt关机命令可以说是这六个关机命令中的老大。
在这个命令中跟上不同的参数,可以实现不同的目的。
在这个关机命令中,主要有如下七个参数。
Linux系统自动关机的命令详解

Linux系统自动关机的命令详解Shutdown命令可以安全地关闭或重启Linux系统,在Linux中可以用shutdown命令实现自动定时关机的功能。
下面由店铺为大家整理了Linux系统自动关机命令详解,希望对大家有帮助!Linux系统自动关机的命令详解Shutdown命令可以安全地关闭或重启Linux系统,在Linux中可以用shutdown命令实现自动定时关机的功能,它在Linux系统关闭之前给系统上的所有登录用户提示一条警告信息。
该命令还允许用户指定一个时间参数,可以是一个精确的时间,也可以是从现在开始的一个时间段。
精确时间的格式是hh:mm,表示小时和分钟,时间段由+ 和分钟数表示。
系统执行该命令后会自动进行数据同步的工作。
该命令的一般格式: Shutdown [选项] [时间] [警告信息]命令中各选项的含义为:- k 并不真正关机而只是发出警告信息给所有用户- r 关机后立即重新启动- h 关机后不重新启动- f 快速关机重启动时跳过fsck- n 快速关机不经过init 程序- c 取消一个已经运行的Shutdown需要特别说明的是该命令只能由Linux超级用户使用。
Linux系统中自动关机命令的具体例子1、shutdown -r now 关机后重启2、shutdown -h now 关机后不重启3、shutdown -r +10 10分钟后重启4、shutdown -r 10:00 10点钟重启5、shutdown -h +10 10分钟后关机6、shutdown -h 10:00 10点钟关机补充:Linux系统的其他的关机重启命令1.halt 最简单的关机命令用halt命令来关机时,实际调用的是shutdown -h。
halt 执行时将杀死应用进程,执行sync系统调用文件系统写操作完成后就会停止内核。
halt 参数说明:[-n] 防止sync系统调用,它用在用fsck修补根分区之后,以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
linux中关机命令
在linux下一些常用的关机/重启命令有shutdown、halt、reboot、及init,它们都可以达到重启系统的目的,但每个命令的内部工作过程是不同的,通过本文的介绍,希望你可以更加灵活的运用各种关机命令。
1.shutdown
shutdown命令安全地将系统关机。
有些用户会使用直接断掉电源的方式来关闭linux,这是十分危险的。
因为linux与windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失﹐使系统处于不稳定的状态﹐甚至在有的系统中会损坏硬件设备。
而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭。
并且login指令会被冻结﹐即新的用户不能再登录。
直接关机或者延迟一定的时间才关机都是可能的﹐还可能重启。
这是由所有进程〔process〕都会收到系统所送达的信号〔signal决定的。
这让像vi之类的程序有时间储存目前正在编辑的文档﹐而像处理邮件〔mail〕和新闻〔news〕的程序则可以正常地离开等等。
shutdown执行它的工作是送信号〔signal〕给init程序﹐要求它改变runlevel。
Runlevel 0被用来停机〔halt〕﹐runlevel 6是用来重新激活〔reboot〕系统﹐而runlevel 1则是被用来让系统进入管理工作可以进行的状态﹔这是预设的﹐假定没有-h也没有-r参数给shutdown。
要想了解在停机〔halt〕或者重新开机〔reboot〕过程中做了哪些动作﹐你可以在这个文件/etc/inittab里看到这些runlevels相关的资料。
shutdown 参数说明:
[-t] 在改变到其它runlevel之前﹐告诉init多久以后关机。
[-r] 重启计算器。
[-k] 并不真正关机﹐只是送警告信号给每位登录者〔login〕。
[-h] 关机后关闭电源〔halt〕。
[-n] 不用init﹐而是自己来关机。
不鼓励使用这个选项﹐而且该选项所产生的后果往往不总是你所预期得到的。
[-c] cancel current process取消目前正在执行的关机程序。
所以这个选项当然没有时间参数﹐但是可以输入一个用来解释的讯息﹐而这信息将
会送到每位使用者。
[-f] 在重启计算器〔reboot〕时忽略fsck。
[-F] 在重启计算器〔reboot〕时强迫fsck。
[-time] 设定关机〔shutdown〕前的时间。
2.halt----最简单的关机命令
其实halt就是调用shutdown -h。
halt执行时﹐杀死应用进程﹐执行sync 系统调用﹐文件系统写操作完成后就会停止内核。
参数说明:
[-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
[-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
[-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
[-f] 没有调用shutdown而强制关机或重启。
[-i] 关机〔或重启〕前﹐关掉所有的网络接口。
[-p] 该选项为缺省选项。
就是关机时调用poweroff。
3.reboot
reboot的工作过程差不多跟halt一样﹐不过它是引发主机重启﹐而halt 是关机。
它的参数与halt相差不多。
4.init
init是所有进程的祖先﹐它的进程号始终为1﹐所以发送TERM信号给init 会终止所有的用户进程﹑守护进程等。
shutdown 就是使用这种机制。
init定义了8个运行级别(runlevel),init 0为关机﹐init 1为重启。
终端模式关机命令有学问
1.“shutdown”实现延迟关机
“shutdown”命令是在Linux文本模式(终端模式)下,使用最多的关机或重启命令。
其使用格式为:“[sudo] shutdown 参数延迟时间”。
“参数”常用的有“-h”和“-r”,“-h”对应关机操作,“-r”对应系统重启(使用“-r”参数时,其功能与Linux系统中的另一个命令“reboot”功能类似)。
“延迟时间”是指从发出命令到真正执行关机或重启操作的延迟时间。
又因该命
令的执行,需要有管理员权限,所以如果当前登录用户(如“root”用户)具有该权限,则无须在“shutdown”命令前加“sudo”,否则需要加上。
“shutdown”命令执行后,将通知所有登录用户系统将要关闭,并停止新用户的登录请求,收到终止信号的用户进程或守护进程也将安全地停止。
细心的读者也许会发现,在Windows系统中也存在一个“shutdown”命令,它的用法与Linux上的“shutdown”命令大同小异,不过需要注意的是它的参数与Linux上的“shutdown”命令有所不同,使用时要注意区分。
另外,Windows系统中“shutdown”命令具有关闭远程计算机的功能,而Linux系统中的“shutdown”命令本身尚不具备该功能。
虽然如此,后面我们会介绍如何在远程登录软件OpenSSH的帮助下,使用“shutdown”命令来实现关闭远程计算机的功能。
2.“poweroff”、“halt”命令快速关机
“poweroff”与“halt”命令都是为与传统System V保持兼容而采用的命令。
在Linux系统中,如没有指定特殊参数,它们都将调用“shutdown”命令并附加“-h”参数来完成关机功能。
该命令的执行要求具有系统管理员权限。
在GNOME终端窗口中直接输入“sudo poweroff”或“sudo halt”命令,将直接关机。
3.“init”、“telinit” 终极关机命令
“init”命令用来切换系统运行级别,传统的System V将系统划分为多个运行级别,包括“0-6”7个级别:
“0”对应系统停机状态;
“1”为单用户状态,类似Windows的安全模式,常用于系统修复;
“2”为多用户状态(没有NFS);
“3”为完全多用户状态(含NFS);
“4”为预留的运行模式;
“5”为多用户图形环境;
“6”是系统重启状态。
很显然,命令“init 0”的作用是由当行运行级别切换到关机状态,而实际执行是向系统的“init”进程发送终止信号,因“init”进程是系统中的“顶级”进程,该进程终止,意味着系统中的用户进程和守护进程等同时终止,即实现了系统关机的功能。
与“init”命令功能相同的命令还有“telinit”命令。
使用“telinit 0”命令也可以实现关机功能。
值得指出的是,“init”与“telinit”命令的执行均需要系统管理员权限。
远程关机SSH来帮忙
如前所述,Windows系统中的“shutdown”命令具有远程关机的功能,只要有
远程计算机上的具有关机权限的用户账号即可。
那么,在Linux系统中如何实现远程关机呢?
如果要关闭网络中的另一台Linux计算机,首先必须要有另一台计算机上的用户账号;其次,另一台计算机支持远程登录,如支持通过SSH安全登录。
这样,我们可以轻松实现远程关机功能了。
假设远程计算机支持SSH远程登录,则远程关闭该计算机的方法有两种:一是登录到该系统后运行前面介绍的各种关机命令来进行关机;另一种是借助于“ssh”命令不用登录也可以进行关机,“ssh”的命令格式为:“ssh –l user remotehost sudo shutdown –h now”。
其中“user”为在远程计算机系统中拥有合法账号的用户,“remotehost”是远程计算机的合法域名或IP地址,“sudo shutdown –h now”则是在远程计算机上以管理员身份执行关机命令。
除了“shutdown”以外,像“halt”、“poweroff”、“init 0”等命令也均可以使用。