1. 程式人生 > >centos7 取消Ctrl+Alt+Del重啟功能

centos7 取消Ctrl+Alt+Del重啟功能

轉載:http://www.cnblogs.com/huangjc/p/4536620.html


 

 

    Linux預設允許任何人按下Ctrl+Alt+Del重啟系統。但是在生產環境中,應該停用按下Ctrl-Alt-Del 重啟系統的功能。

會linux的技術牛們都知道前面的centos版本都是在/etc/inittab中配置,而centos7/RHEL7檢視/etc/inittab檔案,它會告訴你Ctrl+Alt+Del這個功能鍵在哪裡設定。

複製程式碼
[[email protected] ~]# cat /etc/inittab 
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
複製程式碼

現在我們知道了Ctrl+Alt+Del在/usr/lib/systemd/system/ctrl-alt-del.target中配置。

那我們直接vim編輯這個檔案,按以往設定關閉這個功能的方式去操作:全部註釋點/usr/lib/systemd/system/ctrl-alt-del.target檔案中的內容。

 

複製程式碼
[[email protected]_RHEL_B0109-10 ~]# vim /usr/lib/systemd/system/ctrl-alt-del.target

#[Unit]
#Description=Reboot
#Documentation=man:systemd.special(7)
#DefaultDependencies=no
#Requires=systemd-reboot.service
#After=systemd-reboot.service
#AllowIsolate=yes

#[Install]
#Alias=ctrl-alt-del.targe
複製程式碼

 

儲存退出,執行init q重新reload配置檔案。

現在開始執行Ctrl+Alt+Del三鍵組合看看是不是關閉這個功能了!!

果然,這三鍵不生效了,貌似成功了,很高興的說!

然而準備重啟再試試的,reboot下去,等了一會,咋不動了。坑啊,reboot命令竟然不生效了!

 

 

趕緊看看reboot.target這個檔案:

複製程式碼
[[email protected]_RHEL_B0109-10 ~]# cat /usr/lib/systemd/system/reboot.target
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

#[Unit]
#Description=Reboot
#Documentation=man:systemd.special(7)
#DefaultDependencies=no
#Requires=systemd-reboot.service
#After=systemd-reboot.service
#AllowIsolate=yes

#[Install]
#Alias=ctrl-alt-del.target
[
[email protected]
_RHEL_B0109-10 ~]#
複製程式碼

好吧,竟然也全部被登出掉了!看看這是否是軟連結檔案。

[[email protected]_RHEL_B0109-10 ~]# ll /usr/lib/systemd/system/ctrl-alt-del.target
lrwxrwxrwx. 1 root root 13 Mar 19 23:56 /usr/lib/systemd/system/ctrl-alt-del.target -> reboot.target
[[email protected]_RHEL_B0109-10 ~]#

果然顯示ctrl-alt-del.target這是reboot.target的軟連結。

 

經過再三測試,正確方法就是:

delete掉ctrl-alt-del.target這個檔案

再次執行init q重新reload配置檔案。

不用想,成功了!就這樣,這樣,好了......

 

如果要開啟這個功能,方法就是ln -s把軟連結建立回去,再reload一下配置檔案。

 

來源: http://www.cnblogs.com/huangjc/p/4536620.html