微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS创建sudo用户

  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

至此完成相应任务。

参考文献

原文地址:https://www.jb51.cc/centos/374468.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。