1.切换至root用户:
[sunweikai@localhost ~]$ su root
2.查看etc/sudoers权限:
[root@localhost sunweikai]# ls -l /etc/sudoers
如果是只读权限:
-r--r-----. 1 root root 4328 1月 19 2023 /etc/sudoers
3.那么接下来要修改权限为可写:
[root@localhost sunweikai]# chmod u+w /etc/sudoers
4.执行vim命令,编辑/etc/sudoers文件
[root@localhost home]# vim /etc/sudoers
5.按e键直接编辑
6.利用 回车键
换行,找到 Allow root to run any commands anywhere
,按i
键开始编辑,下面的指令会出现插入
的字样
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
7.在root ALL=(ALL) ALL
的下一行添加代码:86god ALL=(ALL) ALL
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
86god ALL=(ALL) ALL
8.按 ESC
键退出插入模式,然后 键盘输入 :wq
关闭并保存
:wq
9.恢复 /etc/sudoers
的权限为440(440权限即为只读权限)
[root@localhost sunweikai]# chmod 440 /etc/sudoers
10.查看/etc/sudoers
的权限是否恢复
[root@localhost sunweikai]# ll /etc/sudoers
-r--r-----. 1 root root 4355 12月 26 19:54 /etc/sudoers
11.权限恢复正常,切换至普通用户(此时已经解决问题,如果还有问题,接着往下看)
[root@localhost sunweikai]# su 86god
su: user 86god does not exist or the user entry does not contain all the required fields
如上图出现了切换用户失败问题(若无问题可跳过)
12.