如何在 CentOS 上创建 sudo 用户
sudo
命令被设计用来允许用户使用其他用户的安全权限运行程序,默认情况下为 root 用户。
在本指南中,我们将向您展示如何在 CentOS 上创建具有 sudo 权限的新用户,您可以使用 sudo 用户在 CentOS 计算机上执行管理任务,而无需以 root 用户身份登录。
创建 sudo 用户
在 CentOS 上,默认情况下 wheel
组中的用户被授予 sudo 访问权限。如果要为现有用户配置 sudo ,就像下面步骤 4 的做法一样,只需将用户添加到 wheel
组中。
按照以下步骤在 CentOS 服务器上创建一个 sudo 用户。
-
首先以
root
用户身份登录 CentOS 服务器。ssh [email protected]_ip_address
-
使用
useradd
命令创建新用户帐户。useradd username
替换
username
为您要创建的用户名。 -
使用此
passwd
命令为新用户设置密码。passwd username
系统将提示您确认密码。确保使用强密码。
Changing password for user username. New password: Retype new password: passwd: all authentication tokens updated successfully.
-
将新用户添加到
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:
结论
打完收工。您已在 CentOS 系统上成功创建了一个 sudo 用户。您现在可以使用此用户在服务器上执行管理任务。