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:
就這樣! 如果您有任何問題,請隨時留下評論。