Add login user to ubuntu system

Preface

At work, sometimes you need to add login users with various permissions under the Linux system. Here are some simple ways to add and delete login users (just replace ichroma with your user name).

1. Add an account with the user's home directory: ichroma

sudo useradd -d /home/ichroma/ -s /bin/bash -m ichroma

2. Add the ichroma user to an account that can execute sudo permissions

# 使 ichroma 用户具有sudo权限
sudo usermod -G sudo ichroma

3. Set (modify) the password of the ichroma account

sudo passwd ichroma
# 根据提示输入两次密码即可,如下图

Insert image description here

4. Clear the password of the specified user ichroma and log in to the system using only the user name.

sudo passwd -d ichroma
# passwd: password expiry information changed.

Insert image description here

5. Delete account ichroma

sudo userdel ichroma     # 只删除用户,但不删除家目录
sudo userdel -r ichroma    # 删除用户,同时删除家目录

6. Modify the name of user user1 to user2

sudo usermod -l user2 user1
# 将 public 改成 dgbamh
sudo usermod -l dgbamh public

7. Lock user user1. After locking, user1 cannot log in.

sudo usermod -L  user1      # 锁定user1
sudo usermod -U user1      # 解锁user1

8. User switching

# 从root用户切换到普通用户rzpan
su - rzpan 
# 或
exit     # 会切换回之前登陆的普通用户
# 从普通用户切换到root用户
sudo -i
# 或
sudo su
# 从普通用户切换到普通用户
su public
# 提示输入public的登陆密码即可

9. User account file

用户账号文件是用于保存用户名称、宿主自录、登录Sell等基本信息,每一行对应一个用户的帐号记录
/etc/passwd:保存用户名称、宿主目录、登录Shell等基本信息
/etc/shadow:保存用户的账号、密码等有效信息

Guess you like

Origin blog.csdn.net/qq_34125713/article/details/129405742