su切换用户到超级管理员免密登陆切换

本文介绍如何在Linux系统中配置特定用户无需密码即可切换至root账户的方法。通过修改su的相关配置文件并设置用户组权限实现免密切换。适用于系统管理员进行高效管理。

linux切换用户命令

su <user>

不过需要密码,怎样做到免密登陆呢?

1.修改/etc/pam.d/su文件

# vim /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

将用户加入到wheel组,比如www用户。

# usermod -G wheel www

# id www
uid=1001(www) gid=1001(www) 组=1001(www),10(wheel)

测试。不用输入密码自动切换到root。

$ su -
上一次登录:三 4月  3 15:38:38 CST 2019pts/0 上

怎样让用户登陆的时候自动切换到root。

建立一个普通用户比如pinet。

# useradd pinet

# passwd pinet
更改用户 pinet 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

# usermod -G wheel pinet

编辑pinet自己家目录下的bash_profile文件。

$ vim .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
su - root # 加入一条授权命令

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值