[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)

linux Ubuntu中报错,XXX is not in the sudoers file. This incident will be reported.

今天在学习的时候,不小心把自己的用户sudo玩坏了(Broken sudo),于是上谷歌搜索XXX is not in the sudoers file. This incident will be reported.
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
看到一些大多数方法都是修改/etc/sudoers文件的内容,由于之前因为修改系统文件除了问题,进入recovery mode又把系统玩崩了(虚拟机),这次我就轻易不想修改系统文件

于是继续看,查到了另一个方法是进入recovery mode修改https://www.tecmint.com/fix-user-is-not-in-the-sudoers-file-the-incident-will-be-reported-ubuntu/
可是我也更不想进入recovery 模式啊~

但我还是仔细的看完了介绍的步骤,继续往下翻,看到许多评论都惊呼用这个方法解决了问题的时候
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
我再往下翻,看到了一个特别的评论:
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
简单解释下就是:
0、你的root需要设置好密码
sudo passwd root
像这样,我以一个新用户user1为例:
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
1、设置好密码之后,就可以切换到root用户:
su root
这里root可以省略,默认就是切换root
像这样
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
2、输入如下指令,将用户名添加到sudoers文件
sudo adduser image sudo
这里的image是我要恢复的用户名,你应该输入你想要恢复的用户名,像这样
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
3、su image(ctrl+d)切回到在使用的用户
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
此时用户image就被添加到了sudoers文件了,又可以使用sudo了:
使用sudo对用户进行修改:
[已解决]user is not in the sudoers file. This incident will be reported.(简单不容易出错的方式)
于是完成,congratulation!果然高手在民间,评论区还是要多逛逛~