CentOS 7快速创建具有sudo权限的普通用户

  • 原创
  • Madman
  • /
  • /
  • 0
  • 7016 次阅读

Synopsis: sudo 命令提供了一种机制,用于向普通用户临时授予通常仅对 root 用户可用的管理员权限。本文演示在 CentOS 上创建具有 sudo 访问权限的新用户的最简单方法,而无需修改服务器的 /etc/sudoers 文件。如果要为已存在的用户配置 sudo,只需跳到步骤 3 即可

1. root 用户登录

root 用户身份登录你的服务器,比如:

Xshell for Xmanager Enterprise 5 (Build 0544)
Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ ssh root@192.168.40.128

Connecting to 192.168.40.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Fri May 31 19:12:53 2016 from 192.168.0.250

2. 添加新用户

1. 创建用户
[root@CentOS ~]# adduser madman

2. 为新用户设置密码
[root@CentOS ~]# passwd madman

3. 将新用户添加到 wheel 组

默认情况下,在 CentOS 中,wheel 用户组的成员具有 sudo 权限

[root@CentOS ~]# usermod -aG wheel madman

4. 测试

列出 /root 目录下的文件需要 root 权限,我们就用它来测试新用户是否已经有 sudo 权限了:

1. 默认情况下,新用户没有 root 权限
[root@CentOS ~]# su - madman
[madman@CentOS ~]$ ls -l /root
ls: cannot open directory /root: Permission denied

2. 在要执行的命令前加 sudo 时,会临时获取 root 权限
[madman@CentOS ~]$ sudo ls -l /root

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 madman: 
total 16
-rw-------. 1 root root 5214 May 31 22:38 anaconda-ks.cfg
-rw-------. 1 root root 5432 May 31 22:38 original-ks.cfg
未经允许不得转载: LIFE & SHARE - 王颜公子 » CentOS 7快速创建具有sudo权限的普通用户

分享

作者

作者头像

Madman

如需 Linux / Python 相关问题付费解答,请按如下方式联系我

0 条评论

暂时还没有评论.

专题系列

文章目录