Linux User and Group management

Source: Internet
Author: User

user profile and password configuration files

User Profile/etc/passwd divided into 7 fields: ① User name ② account password/etc/shadow file ③ user identification number Uid④ Group identification number Gid⑤ Comment Description ⑥ user home directory ⑦ user's shell,/sbin/nologin means no login allowed

Password Profile/etc/shadow divided into 9 fields: ① user name,/etc/passwd corresponding ② user password, Encrypted ③ the date the password was last changed (how many days from 1970.1.1) ④ How many days to change the password, the default is 0, which means that the unlimited ⑤ password expires, that is, how many days must change the password ⑥ password expiration warning period ⑦ account expiration period ⑧ account life cycle, expire after the ⑨ reserved field, meaningless

There are also groups of configuration files/etc/group and corresponding/etc/gshadow; rarely used

User Group Management

Groupadd command: used to create a new workgroup, the new workgroup information will be added to the system files.

Syntax: Groupadd [-G GID] GroupName

Example: Groupadd-g 1008 grptest; View results: Tail-n2/etc/group

groupdel command: used to delete the specified workgroup, the system files to be modified by this command include/ect/group and/ect/gshadow. If some users are still included in the group, you must delete the users before you can delete the groups.

Example Groupdel grptest

Add: View user and owner group using ID root or groups root command

User Management

Useradd command: For new system users created in Linux.

Syntax: Useradd [-u UID] [-G GID] [-D HOME] [-m] [-s]

-U: Represents a custom UID

-G: Represents a group that is already in existence and can be used with a GID or group name

-D: Indicates a custom home directory

-M: Do not set up home directory

-S: Indicates custom shell

Example: Useradd-u 1008-g grp2-d/home/user2-s/sbin/nologin user2

Userdel command: Used to delete a given user, as well as files related to the user. Without the option, only the user account will be deleted, not the relevant files.

Syntax: Userdel [-R] Username;-r: means to delete home directories

Usermod command

Used to modify the user's basic information. The Usermod command does not allow you to change the user account name that is being online.

Syntax: usermod [options] [user name]

Common options:

-G: Modify the group to which the user belongs

-G: Modify the additional group to which the user belongs

-L: Modify account Name

-L: Lock user password

-u: Unlock user password

User Password Management

passwd Password: Used to modify user password

Specify user modifications: passwd user1

Lock user password: passwd-l user1; unlock: Passwd-u user1

Lock users: usermod-l user; Unlock: usermod-u user1

Shell app: Directly modify user password (skip interaction) passwd--stdin User2

Example: Echo "123456" |passwd--stdin user2

Or: Echo-e "123456\n123456" |passwd user2 (-E to achieve line wrapping)

MKPASSWD command

The MKPASSWD command is a tool for generating random passwords, installing: Yum install-y expect

Options:

-L: Specify password length

-D: Specify the number of digits

-C: Specify the number of lowercase letters

-C: Specify the number of uppercase letters

-S: Specify the number of special characters

Example:

Mkpasswd-l 15

Mkpasswd-l 20-s 0

SU command

Used to switch the current user identity to another user identity, the change must enter the user account and password to change.

Common usage:

Su user1 only switches the user

Su-user1 switch to User's home directory while switching users

Su-c ls user2 Specify user identity Execute command

sudo command

Used to allow ordinary users to temporarily have root permissions to execute commands, the default is only root can be used, ordinary users want to use, requires root presets.

Use the Visudo command to go to edit, find # #Allow root to run any commands anywhere line, add one line: User1 all= (All) all

If the user can join the group, find the #%wheel all= (All) all, remove the # on the line; now just add the user to the wheel group.

Restrict root Telnet

This limitation is applicable to SSH Telnet

Open SSH config file/etc/sshd.config, find #permitrootlogin=yes, uncomment, yes to No!

Of course, you also need to restart the SSH service: systemctl restart Sshd.service


Linux User and Group management

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.