環境:VMware下的CentOS
操作:
[shaon@localhost ~]$ sudo apt-get install samba <-----普通用戶shaokn要進行sudo操作
[sudo] password for shaokn: <-----input passwd
shaokn is not in the sudoers file. This incident will be reported.
提示用戶shaokn不在sudoers文件裏.我們要做的就是把shaokn用戶添加到sudoers文件裏,怎麼做呢?
1.進入超級用戶模式.
[shaon@localhost ~]$ su -
Password: <-----input passwd
[root@localhost ~]# <-----root超級用戶
2.添加sudoers文件寫權限.
[root@localhost ~]# chmod u+w /etc/sudoers <-----注意sudoers文件路徑
3.添加shaokn到sudoers文件裏. 在"root ALL=(ALL) ALL"這行下添加"shaokn ALL=(ALL) ALL".
[root@localhost ~]# vim /etc/sudoers
.........................
.........................
root ALL=(ALL) ALL
shaokn ALL=(ALL) ALL <-----添加到這裏. :wq保存退出
.........................
.........................
4.撤消sudoers寫權限. 記得撤消寫權限.
[root@localhost ~]# chmod u-w /etc/sudoers
通過以下4步,成功將shaokn這個用戶添加到sudoers文件裏,當然shaokn也獲得了sudo權限.