[email protected]:~$ sudo /opt/script/ntp.date.sh
[sudo] password for junq:
Sorry, try again.
[sudo] password for junq:
junq is not in the sudoers file. This incident will be reported.
[email protected]:~$
***是你当前的用户名,原因是***用户没有加入到sudo的配置文件里
// 查看sudo user
[email protected]:/etc/sudoers.d# ls -al /etc/sudoers
-r--r----- 1 root root 745 Feb 11 2014 /etc/sudoers
[email protected]:/etc/sudoers.d#
// 给予写权限
[email protected]:/etc/sudoers.d# chmod a+w /etc/sudoers
[email protected]:/etc/sudoers.d# ls -al /etc/sudoers
-rw-rw--w- 1 root root 745 Feb 11 2014 /etc/sudoers
[email protected]:/etc/sudoers.d#
// 修改内容
[email protected]:/etc/sudoers.d# vi /etc/sudoers
[email protected]:/etc/sudoers.d#
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
junq ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
// 去掉写权限
[email protected]:/etc/sudoers.d# ls -al /etc/sudoers
-rw-rw--w- 1 root root 764 Jul 7 20:52 /etc/sudoers
[email protected]:/etc/sudoers.d# chmod a-w /etc/sudoers
[email protected]:/etc/sudoers.d# ls -al /etc/sudoers
-r--r----- 1 root root 764 Jul 7 20:52 /etc/sudoers
[email protected]:/etc/sudoers.d#
// 普通用户,以sudo执行
[email protected]:~$ sudo /opt/script/ntp.date.sh
[sudo] password for junq:
7 Jul 20:53:42 ntpdate[9784]: step time server 202.118.1.81 offset -0.681162 sec
7 Jul 20:53:49 ntpdate[9785]: adjust time server 128.138.141.172 offset -0.014033 sec
[email protected]:~$