ubuntu 设置su,sudo不用输入密码:
sudo visudo
添加yourUserName ALL=(ALL) NOPASSWD: ALL , 后 ctrl+o, 回车 , ctrl+x 退出:
# User privilege specification
root ALL=(ALL:ALL) ALL
yourUserName ALL=(ALL) NOPASSWD: ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
新启动一个terminal, 测试没有生效。
原因: 设了nopasswd,但是不起作用,原因是被后面的group的设置覆盖了。改为添加在文件最后一行即可。
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
yourUserName ALL=(ALL) NOPASSWD: ALL