In Linux, the commands to create users are "useradd" and "adduser", and the command to create passwords is "passwd". The useradd command is used to create a user account, but when creating a new user, the user password is not set, so it cannot be used to log in to the system. You also need to use the passwd command to set the user password. The adduser instruction is a symbolic link to the useradd instruction, and the two are actually the same instruction.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
In Linux systems, you can use the useradd command to create a new user; however, when using this command to create a new user, the user password is not set, so it cannot be used to log in to the system. At this time, you need to use the passwd command to set the user password.
Function description: Create a user account.
Syntax:
useradd [-mMnr][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-s <shell>][-u <uid>][用户帐号]
or
useradd -D [-b][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-s <shell>]
Parameters:
-b, --base-dir BASE_DIR 新账户的主目录的基目录 -c, --comment COMMENT 加上备注文字,备注文字保存在passwd的备注栏中。 -d, --home-dir HOME_DIR 新账户的主目录 -D, --defaults 显示或更改默认的 useradd 配置 -e, --expiredate EXPIRE_DATE 新账户的过期日期 -f, --inactive INACTIVE 新账户的密码不活动期 -g, --gid GROUP 新账户主组的名称或 ID -G, --groups GROUPS 新账户的附加组列表 -h, --help 显示此帮助信息并推出 -k, --skel SKEL_DIR 使用此目录作为骨架目录 -K, --key KEY=VALUE 不使用 /etc/login.defs 中的默认值 -l, --no-log-init 不要将此用户添加到最近登录和登录失败数据库 -m, --create-home 创建用户的主目录(使用-m,如果用户主目录不存在,可以自动创建) -M, --no-create-home 不创建用户的主目录 -N, --no-user-group 不创建同名的组 -o, --non-unique 允许使用重复的 UID 创建用户 -p, --password PASSWORD 加密后的新账户密码 -r, --system 创建一个系统账户 -R, --root CHROOT_DIR chroot 到的目录 -s, --shell SHELL 新账户的登录 shell -u, --uid UID 新账户的用户 ID -U, --user-group 创建与用户同名的组 -Z, --selinux-user SEUSER 为 SELinux 用户映射使用指定 SEUSER
Reference for the above content Linux command api.
Supplementary instructions: useradd can be used to create user accounts. After the account is created, use passwd to set the password for the account, and use userdel to delete the account. The account created using the useradd command is actually saved in the /etc/passwd text file.
Example 1: Create a new user user3, and set the UID to 556, the remark name is "User 03", the home directory is /usr/testuser3, and it belongs to the users group.
1. To view the passwd file, I use the command tac /etc/passwd which means: display the file contents in reverse order ( cat displays in positive order).
/etc/passwd
file records the basic information of each user as A line in the file contains 7 fields. Each field is separated by a colon ":".
The details of the 7 fields are as follows:
(1) User name (user3): User has been created User name, character length 1 to 12 characters.
(2) Password (x): represents the encrypted password stored in the /etc/shadow file.
(3) User ID (556): represents the user’s ID number. Each user must have a unique ID. UID number 0 is reserved for the root user, UID numbers 1 to 99 are reserved for system users, and UID numbers 100-999 are reserved for system accounts and groups.
(4) Group ID (100): represents the ID number of the group. Each group must have a unique GID, which is stored in / etc/group file.
(5) User information (user 03): represents the description field, which can be used to describe the user's information.
(6) Home directory (/usr/testuser3): represents the user’s home directory.
(7) Shell (/bin/bash): represents the shell type used by the user.
2. Check the group to which the user belongs and make sure it is users. Directly: groips user3
or command: id user3 View users and groups , and view their corresponding IDs at the same time.
Example 2: Create a new user account user4, and set the UID to 557, the home directory to /usr/testuser4, the group and user it belongs to The names are the same (use -U). If the home directory does not exist, you can use -m to automatically create the home directory.
Make sure that the group to which user user4 belongs is the same as the user name.
Function description: Set password.
grammar:
passwd [-dklS][-u <-f>][用户名称]
补充说明:passwd指令让用户可以更改自己的密码,而系统管理者则能用它管理系统用户的密码。只有管理者可以指定用户名 称,一般用户只能变更自己的密码。
重要参数:
-d 删除密码。本参数仅有系统管理者才能使用。 -f 强制执行。仅root权限才能操作。 -k 设置只有在密码过期失效后,方能更新。 -l 锁住密码,不能修改密码。仅能通过root权限操作。 -S 列出密码的相关信息。本参数仅有系统管理者才能使用。 -u 解开已上锁的帐号。 -w 在距多少天提醒用户修改密码;仅能root权限操作。
例1:修改用户密码:
功能说明:新增用户帐号。
语 法:adduser
补充说明:在Slackware中,adduser指令是个script程序,利用交谈的方式取得输入的用户帐号资料,然后再交由真正建立帐号的useradd指令建立新用户,如此可方便管理员建立用户帐号。在Red Hat Linux中,adduser指令则是useradd指令的符号连接,两者实际上是同一个指令。
The above is the detailed content of What is the command to create user and password in linux. For more information, please follow other related articles on the PHP Chinese website!