# 查看用户所属组
testu@master:~> groups testu
testu : users
# 查看用户详情
testu@master:~> id testu
uid=1000(testu) gid=100(users) groups=100(users)
# To list all groups on the system:
cat /etc/group
# Create new groups with the groupadd command:
groupadd groupname
# To delete existing groups:
groupdel group
# Add users to a group with the gpasswd command
gpasswd -a user group
# add a user to additional groups with usermod
usermod -aG additional_groups username
# To remove users from a group
gpasswd -d user group
# Modify an existing group with the groupmod command e.g. to rename the old_group group to new_group:
groupmod -n new_group old_group
# -m/--create-home the user's home directory is created as /home/username. The directory is populated by the files in the skeleton directory. The created files are owned by the new user.
# -G/--groups 所属组名 默认组名=username; a comma separated list of supplementary groups which the user is also a member of. The default is for the user to belong only to the initial group
# -s/--shell a path to the user's login shell. Ensure the chosen shell is installed if choosing something other than Bash.
useradd -m -G testu -s /bin/bash testu
useradd -m -s /bin/bash testu
# with the -u/--uid and -g/--gid options when creating the user
useradd -r -u 850 -g 850 -s /usr/bin/nologin username
# To add a new user named archie
useradd -m archie
# Although it is not required to protect the newly created user archie with a password, it is highly recommended to do so:
passwd archie
# To change a user's home directory:
usermod -d /my/new/home -m username
ln -s /my/new/home/ /my/old/home
# To change a user's login name:
usermod -l newname oldname
# To change the user's login shell:
usermod -s /bin/bash username
# User accounts may be deleted with the userdel command:
userdel -r username
# To mark a user's password as expired, requiring them to create a new password the first time they log in, type:
chage -d 0 username