切換到root用戶
[linux@localhost ~]$ su root
密碼:
[root@localhost ~]#
[root@localhost ~]# ll /etc/sudoers
-r--r-----. 1 root root 4030 12月 10 09:55 /etc/sudoers
[root@localhost ~]# chmod 777 /etc/sudoers
[root@localhost ~]# ls -l /etc/sudoers
-rwxrwxrwx. 1 root root 4030 12月 10 09:57 /etc/sudoers
/*username是你的用戶名*/
[root@localhost ~]# echo 'username ALL=(ALL) ALL' >> /etc/sudoers
或者root權限下輸入Visudo 或者 vim /etc/sudoers,找到 root ALL=(ALL) ALL的字段,在下一行追加:
username ALL=(ALL) ALL
5分鍾之后密碼過期,下次需要重新輸入,如果不想如此麻煩,可以用以下方法
username ALL=(ALL) NOPASSWD: ALL
說明:格式為{用戶名 網絡中的主機=(執行命令的目標用戶) 執行的命令范圍}
[root@localhost ~]# chmod 440 /etc/sudoers
[root@localhost ~]# ll /etc/sudoers
-r--r-----. 1 root root 4030 12月 10 09:59 /etc/sudoers
