1 Switch to root user
[[email protected] ~]$ su root
Password:
[Email protected] ~]#
2 View/etc/sudoers file permissions, if read-only permission, modify to writable permission
[Email protected] ~]# ll/etc/sudoers
-r--r-----. 1 root root 4030 December 09:55/etc/sudoers
[Email protected] ~]# chmod 777/etc/sudoers
[Email protected] ~]# ls-l/etc/sudoers
-rwxrwxrwx. 1 root root 4030 December 09:57/etc/sudoers
3 Modify the/etc/sudoers file and execute the following command:
/*username is your user name */
[[email protected] ~]# echo ' username all= (All) all ' >>/etc/sudoers
or root, enter Visudo or vim/etc/sudoers, find the root all= (all) all field, append to the next line:
Username all= (All) all
After 5 minutes the password expires, next time you need to re-enter, if you do not want to be so troublesome, you can use the following methods
Username all= (All) Nopasswd:all
Description: The format of the {user name Network host = (the target user executing the command) execution of the command range}
4 Save exit, and restore/etc/sudoers access rights to 440
[Email protected] ~]# chmod 440/etc/sudoers
[Email protected] ~]# ll/etc/sudoers
-r--r-----. 1 root root 4030 December 09:59/etc/sudoers
5 switch to normal user, test user privilege elevation function
CentOS prompts users not to resolve in the sudoers file using sudo