User Switching in Linux systems (the difference between SU User and Su-user)

Source: Internet
Author: User

1,su command (su is switch user, which is shorthand for switching users)

Format: Su-l USERNAME (-L is login, which is the shorthand for landing, where l can be omitted)

If you do not specify username (user name), the default is root, so the command to switch to root is: su-root or direct Su-

You need to know the user's login password when using SU to switch users

2:SU-the difference from Su

Su-username switch users to a new user's working environment

SU username Switch user, do not change the original user's working directory, and other environment variables directory

3,sudo command

sudo is a privilege management mechanism that relies on/etc/sudoers, which defines which user is authorized to perform the administrative commands as an administrator;

Format: Sudo-u USERNAME COMMAND

When a normal user executes a command by using sudo as root, the-uusername behind sudo can be omitted, that is, sudo COMMAND means sudo is executed by the root user

The difference between 5,sudo and Su

When using SU switch user to know the corresponding user's login password, even if switch to root user identity, need to understand the root user login password. As the root user administrator, how can I authorize other ordinary users to perform root command operations without needing to know the root password? You can use sudo at this point.

4,sudoers file

The configuration file for sudo is:/etc/sudoers.

The sudoers file allows the specified user to run various commands as root, without needing to know the root user's login password. This file must be edited using the Visudo command. (The Visudo command can provide basic sanitychecks and check for parse errors, which provides a quick correctness validity check, as well as a syntax check feature)

View the Sudores file, which has a line that defines allowing the root user to log on from any host, using sudo to switch to any user's identity and execute all commands.

View the sudoers file, which has two lines, as defined by the configuration of the sudo command that the group can use.

A similar article, the two can be complementary, can be used as a reference:

1. The command for user Switching in the Linux system is SU, and the syntax is:

su [-FMP] [-C command] [-s Shell] [--help] [--version] [-] [USER [ARG]]

Parameter description

-F, –fast: Do not need to read the boot file (such as CSH.CSHRC, etc.), only for CSH or tcsh two kinds of shell.

-L, –login: After this parameter is added, it is as if it were re-landed, most of the environment variables (such as home, shell, user, etc.) are based on the user, and

and the working directory will also change. If user is not specified, the default is root.

-M,-p, –preserve-environment: does not change the environment variables when performing su.

-C command: Change the user's username and execute the instruction (command) before changing back to the original user.

Help displaying the description file
–version Display version Information

User: To change the user account,
ARG: The new shell parameter is passed in.

2. Differences between Su [user] and Su-[user]:

su [user] switches to other users, but does not switch environment variables, SU-[user] is the complete switch to the new user environment.

Such as:

[[email protected] ~]# pwd--current directory
/root
[[email protected] ~]# su Oracle--Using SU [user]
[[email protected] root]$ pwd--The current directory does not change, or the previous user directory
/root
[[email protected] root]$ su-oracle--Using Su-[user]
Password:
[[email protected] ~]$ pwd--The current directory becomes the home directory of the current user
/home/oracle
[Email protected] ~]$

Therefore, we recommend that when you switch users, try to use Su-[user], otherwise the environment variables may not be the problem.

User Switching in Linux systems (the difference between SU User and Su-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.