How to temporarily obtain root permissions for common users in CentOS

Source: Internet
Author: User

In actual work, the company does not directly give the root user to the employee, but temporarily obtains the root permission of the system through the employee's own account.

1. My current test environment is: red hat linux 6


[Root @ rhel1 xcg] # uname-aLinux 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, kongzhong and xcg, and set the password.

[The following shows how to create an account.]


[Root @ rhel1 ~] # Useradd xcg [root @ rhel1 ~] # Passwd xcgChanging password foruser xcg. New password: Retype new password: passwd: allauthentication tokens updated successfully.

3. If you are interested in the following, you can switch to the created account and install some software that can only be installed with root permissions to check whether normal users have permissions.

4. There are three methods to grant root permissions:

During the modification, we found that this file is read-only. Therefore, we need to change the permission under the root user to a modifiable permission. After modification, remember to change the permission to the original 440


[Root @ rhel1 ~] # Cd/etc/[root @ rhel1 etc] # ll sudoers-r -- r -----. 1 root 4002Mar 22012 sudoers [root @ rhel1 etc] # chmod 755 sudoers [root @ rhel1 etc] # ll sudoers-rwxr-xr-x. 1 root 4002Mar 22012 sudoers [root @ rhel1 etc] # chmod 440 sudoers # in this step, after modifying the content in/etc/sudoers, restore the permission

(1). Method 1: Modify the/etc/sudoers file, find the following line, and add two lines under root, as shown below:


[Root @ rhel1 ~] # Vim/etc/sudoersroot ALL = (ALL) ALLxcg ALL = (ALL) ALL # The password is required during the switchover, the password is the current normal user's password kongzhong ALL = (ALL) NOPASSWD: ALL # This does not need to be entered during the switch.

After modification, use the xcg and kongzhong accounts to log on,

Then, run the sudo command to execute the corresponding command;

Or run sudo su to temporarily switch to the root user to obtain the root permission.

(2). Method 2: Modify the/etc/sudoers file, remove the comments of the following line, and then change the default group of normal users to wheel.


[Root @ rhel1 ~] # Vim/etc/sudoers % wheel ALL = (ALL) ALL then, modify the common user and make it belong to the wheel group. The command is as follows: [root @ rhel1 etc] # usermod-g wheel kongzhong1

After modification, log on with the kongzhong1 account;

Then, run the sudo command to execute the corresponding command;

Or run sudo su to temporarily switch to the root user to obtain the root permission.

(3). Method 3: Modify the/etc/passwd file, find the following line, and change the user ID to 0, as shown below:


[Root @ rhel1 ~] # Vim/etc/passwdkongzhong2: x: 504: 504: kongzhong2:/home/kongzhong2:/bin/bash after modification: kongzhong2: x: 0: 500: kongzhong2: /home/kongzhong2:/bin/bash

Save. After logging on with the kongzhong2 account, you can directly obtain the permissions of the root account.

The first method is recommended for the above three methods, and the third method is strongly not recommended for the enterprise.


This article from the "no umbrella children must work hard to run" blog, please be sure to keep this source http://634871.blog.51cto.com/624871/1325907


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.