1,切换到root用户
[linux@localhost ~]$ su root
密码:
[root@localhost ~]#
2,查看/etc/sudoers文件权限,如果只读权限,修改为可写权限
[root@localhost ~]# ll /etc/sudoers
-r--r-----. 1 root root 4030 12月 10 09:55 /etc/sudoers
修改为可写权限
[root@localhost ~]# chmod 777 /etc/sudoers
[root@localhost ~]# ls -l /etc/sudoers
-rwxrwxrwx. 1 root root 4030 12月 10 09:57 /etc/sudoers
3,修改/etc/sudoers文件,执行命令如下:
/username是你的用户名/
root权限下输入 vim /etc/sudoers,找到 root ALL=(ALL) ALL的字段,输入:i切换至插入模式,在下一行追加:
username ALL=(ALL) ALL
按esc退出编辑模式,输入:wq,保存并退出。或输入:wq!, 强制保存并退出。
4,恢复/etc/sudoers的访问权限为440
[root@localhost ~]# chmod 440 /etc/sudoers
[root@localhost ~]# ll /etc/sudoers
-r--r-----. 1 root root 4030 12月 10 09:59 /etc/sudoers
5,切换到普通用户,测试用户权限提升功能