linux怎么设置默认启动到字符界面,而非图形界面

CentOS 7以前的版本                                                          

修改 /etc/inittab 文件,将“id:5:initdefault:”这一行的"id:"后的数字(默认为5)改为 3即可。

Linux将X-Window(简称X)仅仅视作一个程序,而不捆绑于其内核之中。在UNIX/Linux中一般将运行级别分为7级(一说九级,但实际应用为六级,保留一级):

0 系统停机
1 单用户模式
2 多用户模式
3 网络多用户模式
4 保留
5 X11模式(即进入图形界面模式)
6 重起

要想修改Linux开机的启动模式(控制台或图形界面等),只需修改/etc/inittab文件。

/etc/inittab文件(部分):
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

要想修改启动级别,将“id:5:initdefault:”这一行的"id:"后的数字(默认为5)改为你要的级别即可。


注意:不要改为0,0表示关机;也不要改为6,否则开机就不停的重启了~  


CentOS 7版本改为以下的方法                                              

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 /etc/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 set a default target, run:
#
# ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target
#
[root@localhost ~]# cat /etc/systemd/system/default.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.

就是说要用

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target


或者

默认运行级别3:systemctl set-default multi-user.target

默认运行级别5:systemctl set-default graphical.target


修改后,启动CentOS无法登录,显示module is unknown     

但是用SSH可以登录,查看日志 tail -n 50 /var/log/secure

Aug 14 21:37:00 localhost login: Module is unknown
Aug 14 21:37:08 localhost login: PAM unable to dlopen(/lib/security/pam_limits.so): /lib/security/pam_limits.so: cannot open shared object file: No such file or directory
Aug 14 21:37:08 localhost login: PAM adding faulty module: /lib/security/pam_limits.so
Aug 14 21:37:12 localhost login: pam_unix(login:session): session opened for user oracle by LOGIN(uid=0)


再看登录验证文件 cat /etc/pam.d/login

发现是使用了32位的验证文件,改为64位的就可以了

#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth       substack     system-auth
auth       include      postlogin
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    include      postlogin
-session   optional     pam_ck_connector.so

session    required     /lib/security/pam_limits.so    ⇒ /lib64/security/pam_limits.so
session    required     pam_limits.so

保存后重启启动,OK!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值