本文參考:
xxx is not in the sudoers file.This incident will be reported.的解決方法
給Linux服務器新建一個user, 設置登陸密碼,然后賦予sudo su root權限。 介紹兩種方式:交互方式,非交互腳本方式
交互方式
新建一個user, 設置登陸密碼
1. 登陸putty, change user
sudo su root
2. add group, group name is usernametest
groupadd usernametest
3. add user and and user to group, user name is usernametest
useradd -d /home/usernametest/ -m -g usernametest usernametest
4. set password password123456
passwd password123456
5. change mod
cd /home/
chmod 775 -R usernametest
給user賦予sudo su root權限: 否則 usernametest 登陸后,執行sudo su root 會報:appsvc is not in the sudoers file. This incident will be reported.
1. 登陸putty, change user
sudo su root
2. 添加sudo文件的寫權限
chmod u+w /etc/sudoers
3. 編輯sudoers文件
vim /etc/sudoers
4. root ALL=(ALL) ALL下一行添加
usernametest ALL=(ALL) ALL
5. 撤銷sudoers文件寫權限
chmod u-w /etc/sudoers
然后user 是 usernametest 時,才可以成功執行命令: sudo su root
非交互方式腳本方式
新建一個user, 設置登陸密碼,然后賦予sudo su root權限
#!/bin/sh
# name=username01
# pass=password01
name=$1
pass=$2
# add user
sudo useradd ${name}
if [ $? -eq 0 ];then
echo "user ${name} is created successfully!!!"
else
echo "user ${name} is created failly!!!"
exit 1
fi
#sudo passwd
echo ${pass} | sudo passwd ${name} --stdin &>/dev/null
if [ $? -eq 0 ];then
echo "${name}'s password is set successfully"
else
echo "${name}'s password is set failly!!!"
fi
# add user to sudoers file
echo "${name} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
echo "${name} add to sudoers file successfully"
