Linux commands, system security-related commands--su

Source: Internet
Author: User

Su

Su is the simplest of the identity switch commands, you can switch any identity, the following first look at its basic parameters.

1[Email protected]:~#su-h2Usage:su[Options] [LOGIN]3 4 Options:5-C,--Command Command Pass command to the invoked Shell6-H,--Help display this Help message and exit7-,-L,--Login                 MakeThe Shell ALoginShell8-M,-p,9--preserve-environment DoNot reset environment variables, andTen keep the same shell One-S,--shell shell use shell instead of the defaultinch passwd

Su does not add any parameters, the default is to switch to the root user, but does not go to the root user home directory, that is, although it is a switch to the root user, but does not change the root login environment, and SU Plus parameters-, the default switch to the root user, and change to the root user's environment. Here's an example to illustrate the difference

Example 1, using Su and SU separately-switch root identity:

1[Email protected]:~$su2 Password:3[Email protected]:/home/gboy#pwd4/home/gboy <== Working directory is still a working directory for ordinary users5[Email protected]:/home/gboy# Exit6 Exit7[Email protected]:~$su-8 Password:9[Email protected]:~#pwdTen/root <== working directory switch to root working directory

* From the example, the Su-command changes to the root user's environment, and the SU command is not, so the Su-(or su-l) command is generally used when switching identities

  

Example 1 allows the user to become the root operating system and wants to run the exit command to leave the root identity. But sometimes we just need to execute a command that requires root, and then restore the original identity when the execution is complete, then we can take advantage of the-C parameter.

Example 2, normal user Gboy execute "head-n 3/etc/shadow" command

1[Email protected]:~$Head-N3/etc/Shadow2 Head: Cannot open '/etc/shadow'For Reading:permission denied <== permissions not enough3[Email protected]:~$su-C"head-n 3/etc/shadow"4 Password: <== Enter root password5root:$6$N 7szr7xj$hmpjocfrwfe8rmmorqk.zhszi/9gqelzcv8/ud9td0rxyxyiv73f7r6f4uwfzggteepvutawyofxab861lsxb/:16635:0:99999:7:: : <== successfully run6daemon:*:15259:0:99999:7:::7bin:*:15259:0:99999:7:::

Linux commands, system security-related commands--su

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.