zoukankan      html  css  js  c++  java
  • Linux CentOS7/RHEL7关闭ctrl+alt+delete功能键

            这是本人测试的经过,纯粹记录来看看,最终解决方法在最后面,中间讲的是遇到的一些坑,可以略过不看!!

           本人操作经验,转载请表明出处: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这个功能键在哪里设置。

    [root@localhost ~]# 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文件中的内容。

    [root@NFJD_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这个文件:

    [root@NFJD_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
    [root@NFJD_RHEL_B0109-10 ~]#

    好吧,竟然也全部被注销掉了!看看这是否是软链接文件。

    [root@NFJD_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
    [root@NFJD_RHEL_B0109-10 ~]#

    果然显示ctrl-alt-del.target这是reboot.target的软链接。

    经过再三测试,正确方法就是:

    deletectrl-alt-del.target这个文件。

    再次执行init q重新reload配置文件。

    不用想,成功了!就这样,这样,好了......

    如果要开启这个功能,方法就是ln -s把软链接创建回去,再reload一下配置文件。

  • 相关阅读:
    unexpected inconsistency;run fsck manually esxi断电后虚拟机启动故障
    centos 安装mysql 5.7
    centos 7 卸载mysql
    centos7 在线安装mysql5.6,客户端远程连接mysql
    ubuntu 14.04配置ip和dns
    centos7 上搭建mqtt服务
    windows eclipse IDE打开当前类所在文件路径
    git 在非空文件夹clone新项目
    eclipse中java build path下 allow output folders for source folders 无法勾选,该如何解决 eclipse中java build path下 allow output folders for source folders 无法勾选,
    Eclipse Kepler中配置JadClipse
  • 原文地址:https://www.cnblogs.com/huangjc/p/4536620.html
Copyright © 2011-2022 走看看