The sudo命令旨在允许用户以另一个用户(默认为 root 用户)的安全权限运行程序。
在本指南中,我们将向您展示如何在 CentOS 上创建具有 sudo 权限的新用户。您可以使用 sudo 用户在 CentOS 计算机上执行管理任务,而无需以 root 用户身份登录。
创建 sudo 用户#
默认情况下,在 CentOS 上,wheel 组中的用户被授予 sudo 访问权限。如果您想为现有用户配置 sudo,只需将您的用户添加到wheel
组,如步骤 4 所示。
请按照以下步骤在 CentOS 服务器上创建 sudo 用户:
1.登录您的服务器#
首先通过登录到您的 CentOS 服务器ssh作为根用户:
ssh root@server_ip_address
2. 创建新用户帐户#
使用以下命令创建一个新的用户帐户useradd命令:
useradd username
Replace username
与您要创建的用户名。
3.设置用户密码#
Run the passwd
为新用户设置密码的命令:
passwd username
系统将提示您确认密码。确保您使用强密码。
Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
4. 添加新用户sudo
group #
默认情况下,在 CentOS 系统上,该组的成员wheel
被授予 sudo 访问权限。将新用户添加到wheel组:
usermod -aG wheel username
如何使用须藤#
Switch给新创建的用户:
su - username
要使用 sudo,只需在命令前面加上前缀即可sudo
和空间。
sudo [COMMAND]
例如,要列出内容
of the /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 用户。您现在可以使用此用户在您的服务器上执行管理任务。
如果您有任何疑问,请随时发表评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)