centos7切换root用户设置无密码

分类:CentOS教程 阅读:83917 次

centos7 下,每当我们使用普通用户切换root用户时,都提示输入密码。但是在某些情况下(比如个人的电脑)就显得有些麻烦。

所以,无密码切换root就有必要了。

centos7/rhel7用户可按照对配置文件进行更改来实现:

配置文件名称:

/etc/pam.d/su

文件更改之前,内容如下:

#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so

更改之后:

#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.s

只需要注意标红的四行的就可理解。从中,也看出来这是系统本身就配置好的,至需要我们稍加修改就能实现。