我的用户名为:liang
输入:sudo vim /etc/sudoers
下图为sudoers的原文件:
- # /etc/sudoers
- #
- # This file MUST be edited with the 'visudo' command as root.
- #
- # See the man page for details on how to write a sudoers file.
- #
- Defaults env_reset
- # Host alias specification
- # User alias specification
- # Cmnd alias specification
- # User privilege specification
- root ALL=(ALL) ALL
- # Allow members of group sudo to execute any command after they have
- # provided their password
- # (Note that later entries override this, so you might need to move
- # it further down)
- %sudo ALL=(ALL) ALL
- #
- #includedir /etc/sudoers.d
- # Members of the admin group may gain root privileges
- %admin ALL=(ALL) ALL
在最后一行加入:liang ALL=NOPASSWD:ALL
- liang ALL=NOPASSWD:ALL
然后,强制保存并退出:wq!
只输入:wq,无法保存,这时千万不要试图修改sudoers的权限,如让它有写权限:
sudo chmod 0640 /etc/sudoer
如果这样的话,下面再用到sudo时,则出错:
sudo: /etc/sudoer is mode 0640,should be 0440
如果出现此情况,解决方法:
1、Ctrl+Alt+F1
2、输入:chmod 0440 /etc/sudoers
3、exit 退出
4、Ctrl+Alt+F7 返回图形模式。
5、再试试sudo命令,则可以
但更糟糕的情况是,如果您root帐户的密码还没有设定,就像我这样。。。
这时,只能进入recovery模式修改了
详见: ubuntu10.4开机如何进入Grub启动界面