Use the sudo command in CentOS

Source: Internet
Author: User

Use the sudo command in CentOS

In linux, because the root permission is too large, it is generally not used. You can only log on to the root user to execute management tasks in some special circumstances. Generally, the su and sudo commands are used for temporary root permissions.

I. Comparison of su and sudo commands:

After entering the su command under a common user, the system will prompt you to enter the password of the root account, and then enter the privileged mode (exactly the same as logging on to the system using the root account). Enter exit or su-user to exit:

$ Su

Password:

# Ls/root

Anaconda-ks.cfg install. log install. log. syslog

# Exit

$ Ls/root

Ls: cannot open directory/root: Permission denied # prompt no Permission [Linux community http://www.linuxidc.com]

With the sudo command, you only need to enter the password of the current user (or you can configure it to do not enter the password) to execute the command that requires the root permission:

$ Ls/root

Ls: cannot open directory/root: Permission denied # The system prompts you that you do not have the Permission.

$ Sudo ls/root

We trust you have got ed the usual lecture from the local System

Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.

#2) Think before you type.

#3) With great power comes great responsibility.

[Sudo] password forOracle: # enter the password of a common oracle user

Anaconda-ks.cfg install. log install. log. syslog

Through the comparison above, we can see that sudo has many advantages over su:

1. Normal users can execute commands that require root permissions without knowing the root password;

2. Do not use the root command to execute destructive commands because you forget to exit (this error is often made by linux beginners );

2. Configure normal users with the permission to use the sudo command:

In linux, the new user does not have the sudo permission. For example, if you create an AAA user, enter the sudo command with the following prompt:

Aaa is not in the sudoers file. This incident will be reported.

This statement means that the user aaa does not exist in the sudoers file, and the time will be reported to the Administrator.

Now that we know the problem is in the sudoers file, let's take a look at the file's sacredness:

[Root @ dbs aaa] # vi/etc/sudoers

# Sudoers allows particle users to run various commands

# The root user, without needing the root password.

##

# Examples are provided at the bottom of the file for collections

# Of related commands, which can then be delegated out to particle

# Users or groups.

##

# This file must be edited with the 'usually do 'command.

# Host Aliases

# Groups of machines. You may prefer to use hostnames (perhaps using

# Wildcards for entire domains) or IP addresses instead.

# Host_Alias FILESERVERS = fs1, fs2

# Host_Alias MAILSERVERS = smtp, smtp2

# User Aliases

# These aren't often necessary, as you can use regular groups

# (Ie, from files, LDAP, NIS, etc) in this file-just use % groupname

# Rather than USERALIAS

# User_Alias ADMINS = jsmith, mikem

Enter I and edit the file. a read-only prompt is displayed at the bottom of the file:

-- INSERT -- W10: Warning: Changing a readonly file

There should be no permission to view the permission after exiting the editing status:

[Root @ dbs aaa] # ll/etc/sudoers

-R -- r -----. 1 root 3825 Jul 22 0:05/etc/sudoers

It turns out that root has only the read-only permission. It is no wonder that you must first modify the permission so that root has full control permissions:

[Root @ dbs aaa] # chmod 740/etc/sudoers

Edit again. The read-only prompt is not displayed this time. Find the following field:

# Allow root to run any commands anywhere

Root ALL = (ALL) ALL

Oracle ALL = (ALL) ALL

Aaa ALL = (ALL) ALL

Add an aaa user, such as aaa ALL = (ALL) ALL

After modification, enter wq to save the modification. After saving the modification, remember to change the permission back. Otherwise, an error message is displayed.

# Chmod 440/etc/sudoers

The permission must be 440. Otherwise, an error message is displayed.

OK. The sudo command can be used normally under the aaa user.

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.