linux用户权限管理(1)-----如何给普通用户提升权限?

su方式

(利用pam_wheel模块,指定个别用户可以切换到root)

切换用户:su - 目标用户
密码验证

  • root --> 其他用户,不需要密码验证
  • 普通用户 -->其他用户,需要目标用户密码

su的优缺点
su 命令的确为管理带来方便,但通过su切换到root后,也有不安全因素。
默认情况下,任何用户都允许使用 su 命令,(如 root)的登录密码,这样带来了安全风险

解决方法
借助于 pamwheel认证模块,只允许极个别用户使用 su 命令进行切换

  • 实现过程:将授权使用 su 命令的用户添加到 wheel 组,修改/etc/pam.d/su 认证配置以启用 pamwheel 认证
[root@xiaoagiao /]# groups user1
user1 : user1

[root@xiaoagiao /]# gpasswd -a user1 wheel     # 为user1添加附加组 wheel
Adding user user1 to group wheel

[root@xiaoagiao /]# groups user1
user1 : user1 wheel
[root@xiaoagiao /]# cat /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                           #将这一行的前边井号去掉,wheel用户安全模块就开启了
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中的用户才可以切换到root用户。

sudo方式

给指定的普通用户开通指定权限

通过 su 命令可以非常方便地切换为另一个用户,但前提条件是必须知道目标用户的登录密码,多一个人知道root密码就多一个风险,使用sudo命令就可以提升执行权限。
这样需要管理员提前进项授权,指定允许哪些用户以超级用户(或其他普通用户)的身份来执行哪些命。

配置文件位置

/etc/sudoers 或者直接使用 visudo打开直接修改

配置文件

[root@xiaoagiao /]# cat /etc/sudoers
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.

## Host Aliases                                                     #主机别名
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2

## User Aliases                                                     #用户别名
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值