Linux User management commands

Source: Internet
Author: User
1Create a new user

[Example 1] Add a user

[Root @ localhost root] # useradd KK // Add User kk

[Example 2] specify a user group for adding a user

[Root @ localhost root] # useradd-g root KK // Add User KK and specify the user group as the root user group

[Example 3] Create a system user

[Root @ localhost root] # useradd-r KK // create a system user kk

[Example 4] specify the home directory for the newly added user

RO [root @ localhost root] # useradd-D/home/Myf KK // Add User KK whose home directory is/home/Myf

When you log on to the host with the user name KK, the default directory/home/Myf is displayed.2Set and modify the User Password passwd

The passwd command is used to set and modify user commands. Only super users and users can change their own passwords. Other common users do not have the right to change the passwords of other users. The command is as follows: [root @ localhost root] # passwd [user name] to avoid the number of characters that have been noticed when a password is entered, linux does not use a password similar to Windows echo (displayed as *). Therefore, these characters cannot be entered.3Modify user information usermod
The usermod command is used to modify user information. The command format is as follows: [root @ localhost root] # usermod [Options] [user name] common command options are 11-20.

Table 4-20 common options of The usermod command
Common options Italian  Yi
-D Update the user's new logon directory
-E Set the end date of the new user. The date format is mm/DD/yy.
-F The account will be permanently suspended several days after it expires. When the value is 0, the account is immediately suspended. If the value is-1, this function is disabled. The default value is-1.
-G Update new user to join Group
-G Define the user as a group member. Each group uses "?" Separated, cannot contain blank characters
-L Change the name of the user during login, and the user directory name will be changed to a new name.
-S Specify New User Shell
-U User ID value, which must be a unique ID value. The USERID of the document directory used under the user directory will be automatically changed. Manually change the document directory that is placed outside the support directory.
For example, the following command modifies user information: [root @ localhost root] # usermod-D/home/user2-S/bin/bash user2 set the main directory path of user2 to/home/user1, set the shell to/usr/bin/GCC. Generally, The usermod command modifies the user account information by referring to the command instructions. However, usermod does not allow you to change the name of an online user account. Therefore, when usermod is used to change the user account information, you must confirm that this user account is not running any Program .

4. Create a group groupadd

The groupadd command is used to create a new user group. The command format is as follows:

[Root @ localhost root] # groupadd [Option] [user name] common options include-G: GID. Unless the-O parameter is used, the value must be unique and cannot be the same. The value cannot be negative. By default, the GID value is increased at least 500. Traditionally, 0-499 is reserved for system accounts.

5Delete user userdel

The userdel command is used to delete existing users and related documents. The command format is as follows:

Common options for [root @ localhost root] # userdel [Option] userdel command:-r deletes documents in the user directory. Documents from other locations will also be found and deleted one by one. Userdel is not allowed to remove online user accounts. Therefore, to delete such user accounts, you must first kill the programs running on the system before deleting the accounts.
6Delete Group groupdel

The groupdel command is used to delete existing user groups. The command format is as follows: [root @ localhost root] # groupdel group name is similar to userdel. If a user in any group is online, the user group cannot be removed. Therefore, if a user in the group is online, it is best to remove the user first and then delete the user.7Switch su between users

   The su command is often used for switching between different users. The command format is as follows:  [Root @ localhost root] # common usage of the SU (User Name) su command is to change to a user or a Super User. If a su command without the user name is issued, the system prompts you to enter the root password, after the input, it can be changed to the root user. If you log on as the root user, you can use the su command to become any user on the system without a password.8View the current online user who

The WHO command is used to view the current online users. This command is very useful. If you want to establish communication with other users, such as using the talk command, you must first make sure that the user is online. Otherwise, the talk process cannot be established. Another example is that the system administrator also needs to use the who command to monitor what each login user is doing at this moment. Common command formats for who commands linux user management commands and common options are as follows: [root @ localhost root] # Who [Options] command who common command options are shown in Table 4-21.              Table 4-21    Command who common Command Options

Common options Italian Yi
- Show all information of all users
-M Displays the user name for running the program, which is the same as "Who am I ".
    -Q Only the user's login account and number of login users are displayed. This option has a higher priority than any other options.
-U The last time the user performed the system operation is displayed after the login user.
-H Show Column Title
All options are optional. For example, run the following command:

[Root @ localhose root] # Who-ah

 9. View user information

[Root @ localhose root] groups // display the user group to which the user belongs

[Root @ localhose root] CAT/etc/passwd | cut-F 1-D: // view all users

 

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.