centos添加用户权限(XXX is not in the sudoers file. This incident will be reported.)

一.问题

新安装的虚拟机在用户使用sudo修改文件权限时提示XXX is not in the sudoers file.  This incident will be reported.

image


二.解决

参考:https://blog.csdn.net/danykk/article/details/80137806

1.使用su命令切换到root用户

(这里有的时候会没有设置root账户的密码,需要先使用sudo passwd root来设置账户密码)

image

2.修改sudoers文件

(1)添加写权限

chmod -v u+w /etc/sudoers

(2)修改文件

sudo visudo

找到root用户行,在下面添加自己的用户行

image

(3)撤销写权限

image

3.测试结果

image


三.用户切换

1. 切换到root

(1)su   (2)sudo su   (3)su root

输入root密码完成切换

2. 普通用户间切换

su username


四.chmod命令

参考:https://blog.csdn.net/ichen820/article/details/115524278

image

posted @ 2022-12-03 01:40  脑袋凉凉  阅读(159)  评论(0编辑  收藏  举报