天天看点

rhel(centos)6/7 切换root用户无密码

rhel(centos)6/7 下,每当我们使用普通用户切换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

当然在对文件的更改完成之后,还需要将用户加入到wheel中

    usermod -G wheel username

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

继续阅读