Under Linux, how can ordinary users temporarily obtain root privileges?

  
In actual work, the company will not directly use the root user to employees, but temporarily obtain the root privileges of the system through the employee's own account. 1. The environment I am testing now is: red hat linux 6 [root@rhel1 xcg]# uname -a Linux rhel1.kongzhong.com 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux 2. Create two common users, respectively kongzhong, xcg; and set the password [The following only demonstrates the creation of an account] [root@rhel1 ~]# useradd xcg [root@rhel1 ~]# passwd Xcg Changing password foruser xcg. New password: Retype new password: passwd: all authentication tokens updated successfully. 3. If you are interested, you can switch to the account you just created, install some software that can be installed only with root privileges, and see ordinary users. Whether there are permissions 4. Give root privileges, there are three ways, as follows: In the modification, we found this file read-only, so we need to change the permissions to modifiable permissions under the root user, after the modification, remember to Permission changed to the original 440 [root@rhel1 ~]# cd /etc/[root@rhel1 etc]# ll sudoers -r--r-----. 1 root root 4002 Mar 2 2012 sudoers [root@rhel1 etc ]# chmod 755 sudoers [root@ Rhel1 etc]# ll sudoers -rwxr-xr-x. 1 root root 4002 Mar 2 2012 sudoers [root@rhel1 etc]# chmod 440 sudoers # This step, after modifying the contents of /etc/sudoers, restore the permissions (1). Method 1: Modify the /etc/sudoers file, find the following line, add two lines under root, as follows: [root@rhel1 ~]# vim /etc/sudoers root ALL=(ALL) ALL xcg ALL =(ALL) ALL # This is the password that needs to be entered when switching. The password is the password of the current normal user. kongzhong ALL=(ALL) NOPASSWD:ALL # This is not required to enter the password when switching. Modify it, use xcg, kongzhong Log in to the account, and then execute the sudo command to execute the corresponding command. Or execute sudo su and temporarily switch to the root user to obtain root privileges. (2). Method 2: Modify the /etc/sudoers file, remove the comment from the following line, and then modify the normal user default group to wheel [root@rhel1 ~]# vim /etc/sudoers %wheel ALL=(ALL) ALL Then Modify the normal user to belong to the wheel group. The command is as follows: [root@rhel1 etc]# usermod -g wheel kongzhong1 After the modification, log in with the kongzhong1 account; then, execute the sudo command to execute the corresponding command; or execute sudo Su , temporarily switch to the root user, get root privileges (3). Method three: modify the /etc/passwd file, find the following line, change the user ID to 0, as follows: 1 2 3 4 [root@rhel1 ~ ]# vim /etc/passwd kongzhong2:x:504:504:kongzhong2:/home/kongzhong2:/bin/bash Modified as follows kongzhong2:x:0:500:kongzhong2:/home/kongzhong2:/bin/bash Save, After logging in with the kongzhong2 account, the direct access to the root account is obtained. The above three methods are recommended to use the first one, and the third one is strongly recommended and will not be used by enterprises. This article is from “Children who don't have an umbrella must work hard & rdquo; blog, please be sure to keep this source http://634871.blog.51cto.com/624871/1325907
Copyright © Windows knowledge All Rights Reserved