Linux Advanced Commands (IX): User-related operations, to know to create user commands

User-related operations


learning target

  • Create a user can know the command

1. Create a user

command Explanation
useradd Create (add) a user

useradd command options:

Options Explanation
-m Automatically create the user's home directory, home directory name is the user name
-g User group the user belongs, do not specify the default will automatically create a user group with the same name

Create a user renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-7Sm5PLeh-1583934985355) (imgs / useradd-1.png)]

View all user information file renderings:
Here Insert Picture Description
[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-5IfB2dkv-1583934985356) (imgs / useradd-2.png)] [image dump outer link fails, the source station there may be security chain mechanism, it is recommended to save the pictures uploaded directly down (img-idlpClUx-1583934985357) (imgs / useradd-3.png)]

Description:

  • useradd use the command requires administrator privileges, front need to add sudo
  • If you do not specify a user to create a user group, the default will automatically create a user group with the same name
  • Check whether the user has been created, you can view ** / etc / passwd ** This file
  • View user group is created, you can check ** / etc / group ** This file

Each information Description passwd file to root❌0: 0: root: / root: / bin / bash as an example:

  • First: Username
  • Second: Password placeholder
  • Third: uid, user id
  • Fourth: gid, user's group id
  • Fifth: user description, optional
  • Sixth: the location of the user's home directory
  • Seventh: The type of shell with a user, typically a bash or sh, sh type is not set by default

Each group file description information to laowang❌1001: for example:

  • The first one: User Group Name
  • Second: password placeholder user groups, user group Linux system generally do not have a password
  • Third: the group id

id command to view the user information:

command Explanation
id View user information

id command renderings:
Here Insert Picture Description
each item of information Description:

uid = 1001 (laowang) gid = 1001 (laowang) group = 1001 (laowang)

  • The first: uid represents the user id
  • Second: gid indicating the user group id
  • Third: Group means that the user where the user group

2. Set password

Other users to set a password, use: sudo passwd username

Password renderings:
Here Insert Picture Description

3. Switch user

command Explanation
his Switch User

Syntax: su - username

FIG handover user effects:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-ndL94Ugu-1583934985358) (imgs / su.png)]

In laowang user sudo -s renderings:

[Image dump the chain fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-LIZfRWMc-1583934985358) (imgs / sudo-s% E9% 97% AE% E9% A2% 98.png )]

Solution:

  • Laowang provided to a user sudo additional group is required to modify the user information usermod

4. Modify User Information

command Explanation
usermod Modify user information

usermod options:

command Explanation
-G An additional group settings
-g Modifying User Groups

usermod command renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-KJE2Fg5b-1583934985359) (imgs /% E9% 99% 84% E5% 8A% A0% E7% BB% 84.png)]

After setting additional groups sudo, the switch to an administrator sudo -s FIG user effects:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-1pTBjFir-1583934985359) (imgs /% E8% AE% BE% E7% BD% AE% E9% 99% 84% E5% 8A% A0% E7% BB% 84% E4% BD% BF% E7% 94% A8sudo-s.png)]

5. Expansion: delete additional groups

command Explanation
gpasswd Add and remove additional group information

gpasswd command options:

Options Explanation
-a username To add additional user groups
-d username To delete additional user group

Delete additional groups renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-Am8amxfR-1583934985359) (imgs /% E5% 88% A0% E9% 99% A4% E9% 99% 84% E5% 8A% A0% E7% BB% 84.png)]

Delete additional group again using sudo -s renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-gY4702zH-1583934985359) (imgs /% E5% 88% A0% E9% 99% A4% E9% 99% 84% E5% 8A% A0% E7% BB% 84% E9% 97% AE% E9% A2% 98.png)]

5. Delete User

command Explanation
userdel delete users

userdel command options:

Options Explanation
-r username Delete the user's home directory must be set, otherwise the user's home directory will not be deleted

Delete User renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-2jtnjOcO-1583934985360) (imgs /% E5% 88% A0% E9% 99% A4% E7% 94% A8% E6% 88% B7-1.png)]

View user id information renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-vJK84Hqs-1583934985360) (imgs /% E5% 88% A0% E9% 99% A4% E7% 94% A8% E6% 88% B7-2.png)]

View group file information renderings:

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-OElf9GVW-1583934985361) (imgs /% E5% 88% A0% E9% 99% A4% E7% 94% A8% E6% 88% B7-3.png)]

Description:

  • Delete a user, the default user group with the same name will be deleted

6. Summary

  • Create a user command format: sudo useradd -m user name , the default will create a user group of the same name.
  • View user information using the id command or / etc / passwd file
  • View user group information using the / etc / group file
  • To the user password using sudo passwd user name
  • Switch users using su - username
  • Set up additional groups using sudo usermod -G group name Username
  • Delete users sudo userdel -r user name , the same name as the default user group will be deleted.
Published 698 original articles · won praise 929 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_35456045/article/details/104806974
Recommended