CentOS user management basics

Source: Internet
Author: User

CentOS user management basics

1) view the current user

[root@moban~]#whoamiroot

2) Add a user

[root@moban~]#useraddxpleaf

Or

[root@moban~]#adduserxpleaf

3) create a password for the user

[root@moban~]#passwdxpleafChangingpasswordforuserxpleaf.Newpassword:Retypenewpassword:passwd:allauthenticationtokensupdatedsuccessfully.

If passwd is not followed by a user, the password is created or modified for the current user by default. However, this method is troublesome, because every time you have to ask and enter two passwords, that is, interactive commands are required. Obviously, it cannot be used to modify user passwords in batches, to modify user passwords in batches, use the following method:

[root@moban~]#echo123456|passwd--stdinxpleafChangingpasswordforuseroldboy.passwd:allauthenticationtokensupdatedsuccessfully.

This method can avoid interaction, but it also has some disadvantages. When using the history command, the modified password is exposed:

[root@moban~]#history388echo123456|passwd--stdinxpleaf

Therefore, after using this method to change the password, we need to clear this history:

[root@moban~]#history-d388# Clear the row number388History input commands[Root @ moban ~] # History-c # Clear all historical input commands

4) Switch users

[1] root-> common users:

[root@moban~]#whoamiroot[root@moban~]#su-xpleaf[oldboy@moban~]$whoamixpleaf

As you can see, you do not need to enter the user password to switch from the root user to the normal user.

[2] normal user-> root:

[oldboy@moban~]$su-rootPassword:

[3] common users-> common users:

[oldboy@moban~]$su-testPassword:

We can see that the password is required for switching from a common user to a root user or a common user.

[4] difference between su and su-

Common su:

[root@moban~]#whoamiroot[root@moban~]#suxpleaf[xpleaf@mobanroot]$

After switching to the xpleaf user, we can see that the [xpleaf @ moban root] $ is followed by root, indicating that the environment variable is the environment variable under the root user. In this case, various problems may occur.

Su -:

[xpleaf@mobanroot]$exitexit[root@moban~]#su-xpleaf[xpleaf@moban~]$

At this time, the environment variable has changed to the environment variable under xpleaf, which is used in the production standard.

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.