ubuntu默认用户sudo不使用密码chunli@ubuntu~$sudovim/etc/sudoers行尾追加一行,防止被其他策略覆盖chunliALL=NOPASSWD:ALL打开一个终端,试试执行sudoapt-getupdate




root@itsm-demo:~# apt-get install -y sudo


root@itsm-demo:~#vim/etc/sudoers为已经存在的user1用户授权##ThisfileMUSTbeeditedwiththe'visudo'commandasroot.##Pleaseconsideraddinglocalcontentin/etc/sudoers.d/insteadof#directlymodifyingthisfile.##Seethemanpagefordetailsonhowtowriteasudoersfile.#Defaultsenv_resetDefaultsmail_badpassDefaultssecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"#Hostaliasspecification#Useraliasspecification#Cmndaliasspecification#UserprivilegespecificationrootALL=(ALL:ALL)ALLuser1ALL=(ALL:ALL)ALL#Allowmembersofgroupsudotoexecuteanycommand%sudoALL=(ALL:ALL)ALL#Seesudoers(5)formoreinformationon"#include"directives:#includedir/etc/sudoers.d强制保存::w!



不需要密码,直接切换到root

pi

chunli

##ThisfileMUSTbeeditedwiththe'visudo'commandasroot.##Pleaseconsideraddinglocalcontentin/etc/sudoers.d/insteadof#directlymodifyingthisfile.##Seethemanpagefordetailsonhowtowriteasudoersfile.#Defaultsenv_resetDefaultsmail_badpassDefaultssecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"#Hostaliasspecification#Useraliasspecification#Cmndaliasspecification#UserprivilegespecificationrootALL=(ALL:ALL)ALL#Allowmembersofgroupsudotoexecuteanycommand%sudoALL=(ALL:ALL)ALL#Seesudoers(5)formoreinformationon"#include"directives:#includedir/etc/sudoers.dpiALL=(ALL)NOPASSWD:ALLchunliALL=(ALL)NOPASSWD:ALL