请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
首页 社区 运维 sudo授权、su切换用户、免密登陆与切换

sudo授权、su切换用户、免密登陆与切换

猿梦 2023-1-3 10:50:46
电线它打死*私孟山灵写错~1、由root用户切换至普通用户:su chenfei2、由普通用户切换至root用户su root但是需要输入密码免密切换root用户的方法:vim /etc/pam.d/su#%PAM-1.0auth            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_uidauth            include         system-authaccount         sufficient      pam_succeed_if.so uid = 0 use_uid quietaccount         include         system-authpassword        include         system-authsession         include         system-authsession         optional        pam_xauth.so保存退出将普通用户添加到wheel组中usermod -G wheel chenfei然后再来切换即可######################################使用ssh或telnet登陆后如何自动切换root:方法:首先切到普通用户:su chenfei然后回到家目录中:cd (cd就可以)修改:vim .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfisudo su - root  #加入这么一个授权的命令# User specific environment and startup programsPATH=$PATHHOME/binexport PATH回到root用户su root  #上面的操作可以实现由普通用户免密切换到root用户,所以这边不用输密码修改sudoers这个文件vim /etc/sudoersroot    ALL=(ALL)       ALLchenfei ALL=(ALL)       NOPASSWD: ALL  #在root后面添加普通用户保存退出切换普通用户可以进行测试: ssh登陆或者sudo su - root或sudo su rootsu root与su - root的区别:实践是检验真理的唯一标准:[chenfei@master ~]$ sudo su root[root@master chenfei]#再看下一个:[chenfei@master ~]$ sudo su - root[root@master ~]#

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册