CentOS创建sudo用户

前端之家收集整理的这篇文章主要介绍了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.f2er.com/centos/374468.html

猜你在找的CentOS相关文章