參考文章:CentOS 7中添加一個新用戶並授權
# root 用戶操作
$ 普通用戶操作
創建用戶
# adduser USERNAME
# passwd USERNAME (輸入密碼)
授權 root 權限
sudo 命令的授權管理是在sudoers文件里的。查看 sudoers 位置:
# whereis sudoers
查看 sudoers 的讀寫權限:
# ls -l /etc/sudoers
如果 sudoers 沒有寫權限則添加:
# chmod -v u+w /etc/sudoers
修改 sudoers:
# vim /etc/sudoers
找到 ## Allow root to run any commands anywher ,修改如下:
root ALL=(ALL) ALL
USERNAME ALL=(ALL) ALL # 這個是新增的用戶
回收 sudoers 寫權限:
# chmod -v u-w /etc/sudoers
使用$ sudo su
命令,輸入密碼切換 root 用戶