Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the Linux system manage the account to add, modify and delete it

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to manage the account in the Linux system and add, modify and delete it". In the daily operation, I believe that many people have doubts about how to manage the account in the Linux system to add, modify and delete it. The editor consulted all kinds of materials and sorted out a simple and useful operation method. I hope it will be helpful for you to answer the question of "how the Linux system manages the account to add, modify and delete it"! Next, please follow the editor to study!

The management of user accounts in Linux system refers to the addition, modification and deletion of user accounts. Because there may be multiple users in the Linux system, the management of user accounts is also common. This article will share with you the tutorial of adding, modifying and deleting user accounts in Linux system.

To add a user account is to create a new account in the system, and then assign resources such as user number, user group, home directory and login Shell to the new account. The account you just added is locked and cannot be used.

Add a new user account

Using the useradd command, the syntax is as follows:

Useradd option user name

The meanings of the options are as follows:

-c comment specifies an annotative description.

The-d directory specifies the user's home directory, and if this directory does not exist, use the-m option at the same time to create a home directory.

-g user group specifies the user group to which the user belongs.

-G user group, which specifies the additional group to which the user belongs.

The-s Shell file specifies the user's login Shell.

The-u user number specifies the user number of the user, and if there is also the-o option, you can reuse the identification number of other users.

The user name specifies the login name of the new account.

For example:

# useradd-d / usr/sam-m sam

This command creates a user sam where the-d and-m options are used to generate a home directory / usr/sam for the login name sam (/ usr is the parent directory where the default user home directory is located).

# useradd-s / bin/sh-g group-G adm,root gem

This command creates a new user gem whose login Shell is / bin/sh, which belongs to the group user group, as well as to the adm and root user groups, where the group user group is its primary group.

To add a user account is to add a record to the new user in the / etc/passwd file, while updating other system files such as / etc/shadow, / etc/group, etc. The contents of these documents will be described in detail later.

Linux provides an integrated system management tool userconf, which can be used to manage user accounts in a unified manner.

If a user's account is no longer in use, it can be deleted from the system. To delete a user account is to delete the user record in system files such as / etc/passwd and, if necessary, the user's home directory. Delete an existing user account using the userdel command in the following format:

Userdel option user name

The common option is-r, which deletes the user's home directory together.

For example:

# userdel sam

This command deletes the records of the user sam in the system files (mainly / etc/passwd, / etc/shadow, / etc/group, etc.) and deletes the user's home directory.

To modify the user account is to change the relevant attributes of the user according to the actual situation, such as user number, home directory, user group, login Shell and so on.

Use the usermod command to modify the information of an existing user in the following format:

Usermod option user name

Common options include-c,-d,-m,-g,-G,-s,-u, and-o, which have the same meaning as the options in the useradd command and can specify new resource values for the user. In addition, some systems can use the following options:

-l New user name

This option specifies a new account, changing the original user name to the new user name.

For example:

# usermod-s / bin/ksh-d / home/z-g developer sam

This command changes the login Shell of user sam to ksh, the home directory to / home/z, and the user group to developer.

One of the important contents of user management is the management of user password. The user account was created without a password, but it is locked by the system and cannot be used. It must be assigned a password before it can be used, even if an empty password is specified.

The Shell command to specify and modify a user password is passwd. Superusers can specify passwords for themselves and other users, and ordinary users can only use it to change their own passwords. The format of the command is:

Passwd option user name

Available options:

-l lock password, that is, disable the account.

The-u password is unlocked.

-d make the account without a password.

-f forces the user to change the password the next time he logs in.

If the default user name is used, the password of the current user is modified.

For example, assuming that the current user is sam, the following command modifies the user's own password:

$passwd

Old password:*

New password:*

Re-enter new password:*

If you are a superuser, you can specify the password of any user in the following form:

# passwd sam

New password:*

Re-enter new password:*

When an ordinary user modifies his password, the passwd command asks the original password first, verifies it, and then asks the user to enter the new password twice. If the password entered twice is the same, the password is assigned to the user, while the superuser does not need to know the original password when assigning the password to the user.

For the sake of system security, users should choose more complex passwords, such as 8-digit long passwords, which contain uppercase, lowercase letters and numbers, and should be different from names, birthdays, and so on.

Assign an empty password to the user

Execute the following form of command:

# passwd-d sam

This command removes the password for user sam so that the next time user sam logs in, the system no longer asks for the password.

The passwd command can also lock a user out of login with the-l (lock) option, for example:

# passwd-l sam

At this point, the study on "how the Linux system manages the account to add, modify and delete it" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report