RHEL and CentOS v6 and v7用户运行模式切换以及用户自动登陆配置

2 篇文章 0 订阅
2 篇文章 0 订阅

前言

RHEL/CentOS有多种系统运行级别,比较常用的多用户模式(3-multi-user mode)和图形界面模式(5-graphical mode),以下为所有的运行模式。

v6-运行级别v7-对应的目标定义
0poweroff.target关机
1rescue.target单用户救援模式
2multi-user.target文字界面多用户模式(v6未启用NFS)
3multi-user.target文字界面多用户文字模式
4multi-user.target文字界面多用户文字模式(v6未用到)
5graphical.target图形界面多用户模式
6reboot.target重启

本文主要讲解v6/v7单次和永久运行模式切换,以及对应模式的自动登陆。

v6运行模式切换以及用户自动登陆

以下适用于RHEL/CentOS v6版本。

1. 单次用户模式切换

init 3 切换到文字界面多用户模式
init 5 切换到图形界面多用户模式

2. 永久用户模式切换

使用指令vim /etc/inittab编辑inittab文件,最后一行id:5:initdefaultid后面的数字即为开机运行模式,3表示文字界面多用户模式,5表示图形界面多用户模式,如下图
模式切换

3. 文字界面多用户模式用户自动登陆设置

使用命令vim /etc/init/tty.conf编辑tty.conf文件,在exec /sbin/mingetty $TTY后面添加参数--autologin root即表示自动登陆root用户

文字界面多用户自动登陆

此处其实是给mingetty命令传递了一个参数进去。如下图是mingetty支持的一些参数,更多参数请查看man page

mingetty参数

4. 图形界面多用户模式用户自动登陆设置

使用命令vim /etc/gdm/custom.conf编辑custom.conf配置文件,在[daemon]后追加如下两行内容:

AutomaticLoginEnable=True
AutomaticLogin=root

即表示开机后进入图形界面自动登陆root用户

图形界面用户自动登陆

v7运行模式切换以及用户自动登陆

以下适用于RHEL/CentOS v7版本。

1. 单次用户模式切换

init 3 切换到文字界面多用户模式
init 5 切换到图形界面多用户模式

2. 永久用户模式切换

systemctl set-default multi-user.target 切换到文字界面多用户模式
systemctl set-default graphical.target 切换到图形界面多用户模式

用户模式永久切换

由上图可以看出,其实在切换过程中,命令相当于执行了一次链接操作,将预设的启动目标链接到/etc/systemd/system/default.target。也就是说其实我们是可以通过手动链接启动模式到这个文件来达到相同的效果。

ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

3. 文字界面多用户模式用户自动登陆设置

使用命令vim /etc/systemd/system/getty.target.wants/getty@tty1.service编辑getty@tty1.service文件,在Service group参数ExecStart=-/sbin/agetty --noclear %I $TERM后添加--autologin root参数来实现自动登陆。

文字界面用户自动登陆

这里其实和v6 中给mingetty命令传递了一个参数类似,v7中实际是给agetty命令传递了一个--autologin root的参数,agetty用于初始化用户终端,支持丰富的参数。如下

Usage:
agetty[options] <line> [<baud_rate>,…] [<termtype>]
agetty [options] <baud_rate>,… <line> [<termtype>]

Open a terminal and set its mode.

Options:
-8, --8bits assume 8-bit tty
-a, --autologin <user> login the specified user automatically
-c, --noreset do not reset control mode
-E, --remote use -r <hostname> for login(1)
-f, --issue-file <file> display issue file
-h, --flow-control enable hardware flow control
-H, --host <hostname> specify login host
-i, --noissue do not display issue file
-I, --init-string <string> set init string
-J --noclear do not clear the screen before prompt
-l, --login-program <file> specify login program
-L, --local-line[=<mode>] control the local line flag
-m, --extract-baud extract baud rate during connect
-n, --skip-login do not prompt for login
-N --nonewline do not print a newline before issue
-o, --login-options <opts> options that are passed to login
-p, --login-pause wait for any key before the login
-r, --chroot <dir> change root to the directory
-R, --hangup do virtually hangup on the tty
-s, --keep-baud try to keep baud rate after break
-t, --timeout <number> login process timeout
-U, --detect-case detect uppercase terminal
-w, --wait-cr wait carriage-return
–nohints do not print hints
–nohostname no hostname at all will be shown
–long-hostname show full qualified hostname
–erase-chars <string> additional backspace chars
–kill-chars <string> additional kill chars
–chdir <directory> chdir before the login
–delay <number> sleep seconds before prompt
–nice <number> run login with this priority
–reload reload prompts on running agetty instances
–help display this help and exit
–version output version information and exit

4. 图形界面多用户模式用户自动登陆设置

使用命令vim /etc/gdm/custom.conf编辑custom.conf配置文件,在[daemon]后追加如下两行内容:

AutomaticLoginEnable=True
AutomaticLogin=root

这里配置方法是和v6一样的。

总结

文字界面多用户模式和图形界面多用户模式自动登陆需执行不同的配置方法,使用于gnome的X11图形管理。按照上面的方法,可以很方便的切换用户模式和配置自动登陆。?

推荐关注博主公众号,获取最新的文章?

服务器测试与运维

?转载请注明来源,版权归作者**@hualong1009**所有, 谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

红糖妹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值