Linux add user group and add user

One, user group

1. Create a user group

  1. Command format
    groupadd 组名
  2. Example
groupadd testgroup # 添加用户组 testgroup 
cat /etc/group | grep testgroup  #查看用户组

2. Delete user group

  1. Command format
    groupdel 组名
  2. Example
groupdel testgroup # 删除用户组

3. View user groups

  1. Command
    cat /etc/groupview all to
    cat /etc/group | grep 组名see if a single exists
  2. Example
cat /etc/group

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
---- 省略 部分----

Second, the user

1. Add users

  1. command
    useradd -m -g 组 新建用户名

-m automatically creates a user's home directory;
-g specifies the user's group

  1. Example
useradd -m -g testgroup zhangsan # 创建用户 zhangsan 指定用户组testgroup

2. Delete user

  1. command
    userdel [options] 用名

options description:
-f force deletion, file
-r removes the user's home directory

  1. Example
userdel -r zhangsan  # 删除用户 zhangsan 同时移除主目录

3. Modify or add password

  1. command
    passwd 用户名
  2. Example
passwd zhangsan # 为用户 zhangsan 新增或修改密码

Three, the problem

1、/usr/bin/xauth: file /home/user/.Xauthority does not exist

The reason for the error:
because the corresponding directory was not authorized when adding a user, only useradd user was executed without authorization of the corresponding user directory

Solution
Execute the following command:

chown username:usergroup -R /home/user_dir

Simultaneous execution usermod -s /bin/bash username(specify shell, otherwise it will be very inconvenient for terminal operation)

Guess you like

Origin blog.csdn.net/small_love/article/details/114282993