su root

增加到管理组

vi /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

去掉第4行注释

添加用户名到wheel用户组:

usermod -G wheel username

增加到sudoers文件中

vim /etc/sudoers
第92行增加(root ALL=(ALL) ALL)下面一行

username    ALL=(ALL)       ALL

sudo的作用就是使当前非root用户在使用没有权限的命令 时,直接在命令前加入sudo,在输入自己当前用户的密码就可以完成root用户的功能,而不必在每次使用su -来回切换用户了。sudo的配置文件位于/etc/sudoers,需要root权限才可以读写。
找到root ALL=(ALL) ALL这一行,在后面再加上一行就可以了(不用引号):
username ALL=(ALL) ALL
其中username为指定的使用sudo的用户,引号内的空格为tab
如果你想每次使用sudo命令的时候都提示你输入根密码,移动到这一行:
#%wheel ALL=(ALL) ALL
解除#号注释
如果你不想每次使用sudo命令的时候都提示你输入跟密码,移动到下面这一行:
#%wheel ALL=(ALL)NOPASSWD:ALL
解除#号注释
保存后退出
添加用户名到wheel用户组:
usermod -G wheel username

猜你喜欢

转载自blog.csdn.net/u013193903/article/details/80365423
今日推荐