How to add and delete user accounts in Linux system

  
                

Management of Linux system squadron user accounts refers to adding, modifying, and deleting user accounts. Because there may be multiple users in a Linux system, the management of user accounts is also very common. This article will share the tutorial on adding, modifying, and deleting user accounts for Linux systems.

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

Adding a new user account

Using the useradd command, the syntax is as follows:

useradd option username

The options are as follows:

-c comment Specifies an annotative description.

-d directory Specifies the user's home directory. If this directory does not exist, the home directory can be created with the -m option.

-g User Group Specifies the user group to which the user belongs.

-G User Group, User Group Specifies the additional group to which the user belongs.

-s Shell File Specifies the user's login shell.

-u User Number Specifies the user number of the user. If there is also the -o option, the identification number of other users can be reused.

Username Specify the login name of the new account.

For example:

# useradd –d /usr/sam -m sam

This command creates a user sam with the -d and -m options for The login name sam generates a home directory /usr/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, the user's login shell is /bin/sh, it It belongs to the group user group and belongs to the adm and root user groups. The group user group is its primary group.

Adding a user account means adding a record to the new user in the /etc/passwd file and 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 used, it can be removed from the system. To delete a user account is to delete the user record in the system file such as /etc/passwd, and delete the user's home directory if necessary. Delete an existing user account using the userdel command, the format is as follows:

userdel option Username

The commonly used option is -r, which is used to delete the user's home directory.

For example:

# userdel sam

This command deletes the user sam in the system file (mainly /etc/passwd, /etc/shadow, /etc/group, etc. ) the record while deleting the user's home directory.

Modifying the user account is to change the user's related properties, such as user number, home directory, user group, login shell, etc. according to the actual situation.

Modify the information of existing users using the usermod command, the format is as follows:

usermod option User name Previous12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved