sudo 命令旨在允许使用者使用其他使用者的安全许可权执行程式,预设情况下是 root 使用者。 在本指南中,我们将向您展示如何在 CentOS Linux 7.5 上建立具有 sudo 许可权的新使用者。
建立 sudo 使用者的步骤
1)以 root 使用者身份登入到您的 CentOS 站群服务器:
ssh root@server_ip_address
2)使用 useradd 命令建立一个新的使用者帐户:
useradd username
将 username 替换为您要建立的使用者名称。
3)使用 passwd 命令为新使用者设定密码:
passwd username
输出:
Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
4)将新使用者新增到组成员。
usermod -aG wheel username
找到授予 sudo 访问权的档案中的行
在 CentOS 预设情况下,组轮中的使用者被授予 sudo 访问许可权。
如何使用 sudo
切换到新建立的使用者:
su – username
要使用 sudo,只需在命令前加上 sudo 和一个空格即可。
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:
就这样! 如果您有任何问题,请随时留下评论。