In Linux, how to add, modify, delete, pause, and freeze user names

Source: Internet
Author: User

In Linux, how to add, modify, delete, pause, and freeze user names

Before adding, modifying, and deleting usernames, recognize two of the most important files in Linux, which are the most important files for account management: "/etc/passwd" and "Etc/shadow".

Environment : Windows 7 + VirtualBox + Fedora KDE

1. Recognize the "etc/passwd" file

At the command line, enter: VI/ETC/PASSWD

Open the/etc/passwd file as shown in.

File Construction: Each line represents an account, and a few lines represent several accounts in the system. Special note is that many of the accounts in the system must be, called system accounts, such as bin, Daemon, ADM and nobody. These accounts are necessary for the normal operation of the system, and should not be deleted at random.

The meanings of each part of each line are explained in the first example.

Root:x:0:0:root:/root:/bin/bash

The sections of the line are separated by ":", with a total of 7 sections, namely:

The first part: root is the account name, corresponding UID.

Part Two: x indicates that the password has been moved to the shadow encrypted file.

The third part: 0 is the UID, that is, the user identification code. When the UID is 0 Yes, the account is "system administrator". The UID is generally reserved for use by the system in 1~499, and in 500~65535 for general users.

The fourth part: 0 is GID, that is, user group identification code, and/etc/group.

Part V: Root is the user information description bar, used to explain the meaning of the account.

Part VI:/ROOT is the user's home directory.

Part VII:/bin/bash is the shell used to communicate between the interfaces of each hardware device when the command is executed.

2. Recognize the "/etc/shadow" file

command line input: # Vi/etc/shadow

Open the/etc/shadow file as shown in.

The purpose of each of the sections in each line is described in the first behavior example below.

Root:$6$jefz355e$jbpbwazwdn7izenskhbbywn/9ydvpdwc787bs3krrwwkwl.xut/pjjvgamfo7vblvsyhv3snx8lwwa88f54gd. : 15952:0:99999:7:::

Shadow with ":" As a delimiter, 9 fields, the use of the following:

The first part: account name root. Because the password needs to correspond with the account, therefore, this file's first column is the account number, must be same as/etc/passwd.

Part II: Password $6$jefz355e$jbpbwazwdn7izenskhbbywn/9ydvpdwc787bs3krrwwkwl.xut/ Pjjvgamfo7vblvsyhv3snx8lwwa88f54gd., is the encoded password.

Part III: Date 15952 of the most recent password change. Note that the time of the Linux date is 1970.1.1 as 1.

Part IV: The number of days that the password cannot be changed is 0, which can be changed at any time.

Part five: The password needs to be re-changed in the number of days 99999, indicating the password does not need to be re-entered.

Part VI: The warning period before the password change period is 7, the user will be alerted within 7 days before the password expires.

Part VII: The grace period of expiration of the password, which means that it cannot be logged on.

Part: The expiration date of the account. This field is no longer available after the date is specified. This field is typically used in a system that has a "paid service".

Ninth part: Reserved.

3. Add a user

(1) Fully reference the default value to create a user named Vbird

Command line type: # Useradd Vbird

(2) View Vbird user situation

Command line type: # Ls-l/Home

You can see that the home directory has been automatically created for Vbird users.

(3) View Vbird user status in/etc/passwd,/etc/shadow,/etc/group

Command line type: # grep Vbird/etc/passwd/etc/shadow/etc/group

As you can see, information is added to the Vbird user in all three files.

(4) in the corresponding line of/etc/shadow, you can see that the password area corresponds to "!!", indicating that the Vbird user has no password. If you do not have a password, you cannot log in to the user, and use the passwd command to set the password for the user.

Command line type: # passwd Vbird

Password specification is very complicated, simple password will remind "bad Passwd:is too Easy", but enter this password again, the system will accept your password.

Take a look at the Vbird user information in/etc/shadow

Command line type: # grep Vbird/etc/shadow

As you can see, the cipher area already has the content (the encoded result, of course).

4. Modify a user

When you modify a user, you use the Usermod command primarily, or you can use the method of manually modifying the file. If your foundation is not strong, it is recommended to use the USERMOD command to modify it.

(1) Change user name Vbird to Vbirdfly

Note : Shutdown (Shutdown), and then the root user to log on to the system to successfully modify the user name, only exit (layout) is not possible.

Command line type: # usermod-l vbirdfly Vbird

Vbird user has successfully named Vbirdfly, but its home directory and password are still original Vbird.

Exit (layout) system, and then re-login with the Vbird user and the original password, has been unable to log in, and with the Vbirdfly user and the original password login, you can successfully log in.

(2) How can I change the home directory to vbirdfly?

• Command version

Note: Shutdown (shutdown), and then the root user login system to successfully modify, only exit (layout) is not possible.

Command line type: # usermod-d/home/vbirdfly-m vbirdfly

As you can see, the Home directory section of/ETC/PASSWD has been modified to/home/vbirdfly. What are the changes made under/home? As you can see, the original Vbird file was changed to Vbirdfly file. Here you need to explain the-D and-M parameters of Usermod:

If the command is usermod-d/home/vbirdfly vbirdfly indicates that only the contents of the/etc/passwd 6th column are modified, and if you add the-m parameter, which is the command usermod-d/home/vbirdfly-m Vbirdfly, the Indicates a new home directory, and if the original home directory is/HOME/VIBRD, then the usermod-d/home/vbirdfly-m vbirdfly command will rename the original/home/vbird to/home/vbirdfly.

• Manual Version

First, change the name of the home directory to vbirdly

Command line type:

# Cd/home

# MV Vbird Vbirdfly

You can see that the home directory has successfully modified the name.

It's not enough, we need to make another change in the/etc/passwd.

Command line type: # VI/ETC/PASSWD

Change the Red box section to Vbirdfly

Exit (layout) system, we vbirdfly again to see!

As can be seen, Vbirdfly is to/home/vbirdfly for home directory, modify success!

5. Delete a user

Deleting a user means not changing the user to use any data on the host and deleting the user's data.

Note: Shutdown (shutdown), and then the root user login system to successfully modify, only exit (layout) is not possible.

The command used is Userdel

Input command: # userdel-r Vbird

You can see that the user has been deleted (including home directories).

If Vbird has been operating for a period of time, the system may contain other files, such as mail messages (email box), routine commands (crontab) such as files, so want to completely delete the account, the final execution Userdel-r username, first to "Find/- User username "Find the files that belong to username in the entire system and then delete them."

6. Pausing a user

If you just want a user to "temporarily not enable", set the last derivative of the/etc/shadow field to 0 so that the account can not be used.

Refer to the above/etc/shadow introduction, the account immediately invalid.

7. Freezing a user

If you just want a user to be unable to log in, or the password freezes, you can use the passwd command.

# passwd-l Username

Will show:

Locking Password for user username

Passwd:success

Password Freeze unlock

# passwd-u Username

Note: username is just to illustrate that the operation is simply replaced with its own user name.

In Linux, how to add, modify, delete, pause, and freeze user names

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.