刚装完centos无法设置root初始密码/无法使用sudo命令
使用sudo passwd root报错xxx is not in the sudoers file. This incident will be reported.使用 su root报错su: Authentication failure同时用户没有权限修改sudoers文件,问题似乎进入了死循环?
可以使用pkexec命令和pkttyagent命令解决该问题。
打开两个命令行终端,第一个使用命令获取PID
echo $$ 获取pid
第二个使用命令,然后命令行会卡住
pkttyagent -p pid
第一个再输入命令,同时输入当前用户的密码,这个命令使用完后命令行也会卡住
pkexec visudo
这个回到第二个终端,输入密码
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: root
Password:
提示 ==== AUTHENTICATION COMPLETE === 后回到第一个终端
编辑文本,仿照root = ALL (ALL) ALL 加上自己的权限
xxx = ALL (ALL) ALL,保存退出,这个时候就可以使用sudo命令激活root了。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
xxx ALL=(ALL) ALL