Linux commands -- su, sudo, and Linux Command -- susudo

Source: Internet
Author: User

Linux commands -- su, sudo, and Linux Command -- susudo

The role of the su (switch user) command: switch between users, usually between common users and root users.
Example:
> Su # enter the su command
Password: # enter the Password

Related commands: su-and sudo

I. What is the difference between the su command and the su-command in Linux?
Su switches to other users, but does not switch the environment variables (for example, the export command can be used to check the differences between the two Commands)
Su-completely switches to a user environment
We recommend that you use su-root whenever possible when switching users. Otherwise, some commands may fail to be executed.
From the Super User root to a common user, enter the exit command.

Ii. Differences between su and sudo in Linux
Because su (or su-root) has no permissions after switching to the super-Permission User root, all root permissions can be used.
If multiple common users switch to the root user to perform operations on the system at the same time, different users may perform different operations on the same file, which is not safe.
The sudo command can solve the problem by specifying which users are responsible for the operation and which command is used to complete the operation.
Through sudo, we can grant specific permissions of some root accounts to common users without having to know the root password.
Therefore, sudo is safer than su with unrestricted permissions. Therefore, sudo is called restricted su or authorized su.
The sudo command execution process is that the current user switches to the root (or another specified user), and then runs the command as root (or another specified user ).
After the execution is completed, it is directly returned to the current user. The premise is to modify the configuration file/etc/sudoers for authorization.

3. to configure sudo, the super user must use mongodo to edit the/etc/sudoers file. There are two reasons for using mongodo to edit the file:
First, it can prevent two users from modifying it at the same time; second, it can also perform limited syntax checks.

If the following line is written to the sudoers file:
Tomcat ALL = (ALL) ALL
The first "ALL" refers to the host in the network. We will change it to the host name later, which indicates that tomcat can execute the subsequent commands on this host; (you can run the hostname command to view the Host Name of the linux server)
The "ALL" in the second bracket refers to the target user and the identity of the target user to execute commands;
The last ALL indicates the command name.
After the preceding statement is written, it indicates that tomcat and root have the same permissions and can be used by any command. In this way, the system is too insecure,
Let tomcat users execute some commands (for example, ifconfig and ls) and write the following line in the sudoers file:
Tomcat hostname =/sbin/ifconfig,/bin/ls

Run the following command on the crt:
[Tomcat @ localhost ~] $ Sudo ls/root
PassWord:
At this point, the problem is: after logging on, you need to enter the password each time you use sudo. If you do not want to enter the password when using the sudo command, modify the configuration file as follows:
Tomcat localhost = NOPASSWD:/bin/cat,/bin/ls
When you use the sudo cat or sudo ls command again, you will not be prompted to enter the password.

 

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.