Ubuntu系统为用户添加sudo权限

系统:Ubuntu 18.04 LTS,使用sudo执行命令时提示:XXX is not in the sudoers file. This incident will be reported. 没有sudo权限,解决方法如下:

使用root用户登录

#给/etc/sudoers文件写入权限
chmod u+w /etc/sudoers

#编辑/etc/sudoers文件
vi /etc/sudoers

/etc/sudoers文件中的#User privilege specification下增加需要使用sudo的用户,添加到root这一行的下面即可,也可以复制root这一行,把root改成你的用户名。:wq保存退出。

#撤消/etc/sudoers的写入权限
chmod u-w /etc/sudoers

参考: https://blog.csdn.net/u012897374/article/details/78827359