centos新增普通使用者禁止root登入並新增sudo許可權
阿新 • • 發佈:2019-01-10
1. 新增使用者
adduser username
2. 設定密碼
passwd ***
此時一個使用者就已經新增完成了,但是此時這個使用者是不能使用sudo命令化身root許可權的,需要root許可權配置如下:
//第一步 找到sudoers檔案
whereis sudoers
//第二步 獲取修改許可權
chmod 777 /etc/sudoers
//第三步 開啟檔案並編輯
vim /etc/sudoers
//找到root ALL=(ALL) ALL一行 在下面新增新增的使用者按照root的格式
username ALL=(ALL) ALL
//儲存退出
:wq
//第四步 修改許可權為只讀
chmod 444 /etc/sudoers
//最後一步 重新整理許可權
systemctl restart sshd
此時新增的使用者已經可以使用sudo化身root使用者了,最後就是禁止root登入
//找到sshd_config檔案
whereis ssh
//獲取最高許可權
chmod 777 /etc/ssh/sshd_config
//編輯檔案 找到PermitRootLogin yes一行 將yes修改為no
PermitRootLogin no
//儲存退出
:wq
//修改許可權為只讀
chmod 444 /etc/ssh/sshd_config
//重新整理許可權
systemctl restart sshd
//此時root使用者已經無法登入