sudo控制用户权限实战操作

本文介绍了Linux系统中sudo命令的使用,强调了它在权限管理上的便利性,如避免记住多个root密码,提供审计功能等。通过创建并配置test用户,展示了如何添加用户到特定组,控制用户对特定命令的访问权限,以及如何通过编辑sudoers文件实现更细粒度的权限控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sudo命令的好处就是可以普通用户不需要知道root用户的密码,也可以进行root用户还能进行的操作,只需要输入普通用户自己的密码就行

它可以实现比su命令更细粒度的操作

如果我们有很多服务器,每个服务器root用户密码不一样,需要把用户密码逐个记下来,但是用了sudo,我们只需要记住普通用户的密码就行,不需要知道root用户的密码

使用sudo还有一个好处就是,如果系统有很多运维人员,每个人都通过自己账号的sudo来操作系统,万一出错了,sudo可以提供审计,如果每个人都是使用root来操作系统,万一操作错误,就不好追查是哪个用户操作的了。

新建一个测试用户,并给用户设置密码

[root@10-13-53-194 ~]# useradd test
[root@10-13-53-194 ~]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@10-13-53-194 ~]#

未对test用户做任何sudo命令相关的设置,切换到新建的test用户

[root@10-13-53-194 ~]# su - test

[test@10-13-53-194 ~]$ sudo -l

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for test:
Sorry, user test may not run sudo on 10-13-53-194.

[test@10-13-53-194 ~]$ sudo ls /root
[sudo] password for test:
test is not in the sudoers file.  This incident will be reported.
[test@10-13-53-194 ~]$
[te
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值