How to manage sudo users in Centos

本文介绍如何在CentOS系统中创建新用户,并通过将其加入wheel组来授予该用户执行sudo命令的权限,同时展示了设置用户密码及使用sudo执行更新操作的过程。

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

  sudo命令提供了临时使用root权限的机制,使普通用户可以执行超级管理员任务。

  我要在CentOS系统上创建一个新用户,并且有执行sudo命令的权限。我并不直接修改sudoers文件。

  首先创建一个新用户,如果你使用已存在的用户,可以跳过这一步。只有root用户有权限添加新用户:

[root@centos ~]# adduser lwk

把username替换为你的用户名。

设置用户密码:

[root@centos ~]# passwd username
[root@centos ~]# passwd lwk
Changing password for user lwk.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@centos ~]# 

现在这个用户并不能执行root任务。

把用户添加到wheel组

[root@centos ~]# usermod -aG wheel lwk

在CentOS上,wheel组里的成员有执行sudo的权限。

测试
使用su命令切换到新用户:

[root@centos ~]# su - lwk
Last failed login: Tue Apr 17 11:16:18 CST 2018 from 192.168.2.182 on ssh:notty
There were 10 failed login attempts since the last successful login.
[lwk@centos ~]$ 

执行root任务:

[lwk@centos ~]$ sudo yum update
[sudo] password for lwk: 
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
base                                                                                              | 3.6 kB  00:00:00     
extras                                                                                            | 3.4 kB  00:00:00     
gitlab_gitlab-ce/x86_64/signature                                                                 |  836 B  00:00:00     
gitlab_gitlab-ce/x86_64/signature                                                                 | 1.0 kB  00:00:00 !!! 
gitlab_gitlab-ce-source/signature                                                                 |  836 B  00:00:00     
gitlab_gitlab-ce-source/signature                                                                 |  951 B  00:00:00 !!! 
jenkins                                                                                           | 2.9 kB  00:00:00     
updates                                                                                           | 3.4 kB  00:00:00     
(1/2): jenkins/primary_db                                                                         |  23 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                | 6.9 MB  00:00:01     
(1/2): gitlab_gitlab-ce-source/primary                                                            |  175 B  00:00:02     
(2/2): gitlab_gitlab-ce/x86_64/primary                                                            | 1.2 MB  00:00:03     
Determining fastest mirrors

至此完成相应任务。

参考文献

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值