如何在CentOS上创建Sudo用户

时间:2020-03-05 15:26:23  来源:igfitidea点击:

sudo命令旨在允许用户使用其他用户(默认情况下为root用户)的安全特权运行程序。

在本教程中,我们将向我们展示如何在CentOS上创建具有sudo特权的新用户。
我们可以使用sudo用户在CentOS计算机上执行管理任务,而无需以root用户身份登录。

创建Sudo用户

在CentOS上,默认情况下,对转轮中的用户授予sudo访问权限。
如果要为现有用户配置sudo,只需将用户添加到“ wheel”组,如步骤4所示。

请按照以下步骤在CentOS服务器上创建sudo用户:

1.登录到服务器

首先以root用户身份通过ssh登录到CentOS服务器:

ssh root@server_ip_address

2.创建一个新的用户帐户

使用useradd命令创建一个新的用户帐户:

useradd username

用我们要创建的用户名替换“用户名”。

3.设置用户密码

运行“ passwd”命令为新用户设置密码:

passwd username

系统将提示我们确认密码。
确保使用强密码。

Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

4.将新用户添加到“ sudo”组

在CentOS系统上,默认情况下,“ wheel”组的成员被授予sudo访问权限。
将新用户添加到wheel组:

usermod -aG wheel username

如何使用Sudo

切换到新创建的用户:

su - username

要使用sudo,只需在命令前加上“ sudo”和空格即可。

sudo [COMMAND]

例如,要列出“/root”目录的内容,可以使用:

sudo ls -l /root

首次从该帐户使用sudo时,我们将看到以下横幅消息,并提示我们输入该用户帐户的密码。

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 username: