ubuntu未启用root用户时,修改/etc/sudoers出错后解决方法

机器上折腾了一个ubuntu环境,做了大量的定制,准备克隆给其他设备用,结果今天有一个需求需要修改/etc/sudoers,我直接vim修改,拿掉了#include的#号,结果悲剧了,sudo无法执行了。

# 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

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

并且由于之前我没添加root用户,切root修改都不行,瞬间崩溃,这系统折腾了我3天了,马上要搞好了,难不成要重新来一遍?我详细记录了整个定制的过程,大不了花点时间重新来。但是我不甘心啊,google后,发现用pkexec可以提权,但是我执行

pkexec vim /etc/sudoers

后发现,即便我输入正确的密码,也提升鉴权失败,巨恶心,好在看到了这篇文章,原来是因为我执行pkexec是通过ssh来的,得到本机上执行才行,果然解决了。

posted @ 2023-05-19 11:48  thammer  阅读(66)  评论(0编辑  收藏  举报