ubuntu默认用户sudo不使用密码chunli@ubuntu~$ sudo vim /etc/sudoers行尾追加一行,防止被其他策略覆盖chunli ALL = NOPASSWD: ALL打开一个终端,试试执行sudo apt-get updateroot@itsm-demo:~# apt-get install -y sudo
root@itsm-demo:~# vim /etc/sudoers为已经存在的user1用户授权## This file MUST be edited with the 'visudo' command as root.## Please consider adding local content in /etc/sudoers.d/ instead of# directly modifying this file.## See the man page for details on how to write a sudoers file.#Defaults env_resetDefaults mail_badpassDefaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specificationroot ALL=(ALL:ALL) ALL user1 ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command%sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.d强制保存::w!
不需要密码,直接切换到root
pi
chunli
## This file MUST be edited with the 'visudo' command as root.## Please consider adding local content in /etc/sudoers.d/ instead of# directly modifying this file.## See the man page for details on how to write a sudoers file.#Defaults env_resetDefaults mail_badpassDefaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specificationroot ALL=(ALL:ALL) ALL# Allow members of group sudo to execute any command%sudo ALL=(ALL:ALL) ALL# See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.dpi ALL=(ALL) NOPASSWD: ALLchunli ALL=(ALL) NOPASSWD: ALL