search
HomeOperation and MaintenanceLinux Operation and MaintenanceWhat is the command to create user and password in linux

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.

What is the command to create user and password in linux

#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.

Command: useradd

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.

Command: passwd(password)

Function description: Set password.
grammar:

passwd [-dklS][-u <-f>][用户名称]

 补充说明:passwd指令让用户可以更改自己的密码,而系统管理者则能用它管理系统用户的密码。只有管理者可以指定用户名                     称,一般用户只能变更自己的密码。

 重要参数:

  -d  删除密码。本参数仅有系统管理者才能使用。 
  -f  强制执行。仅root权限才能操作。 
  -k  设置只有在密码过期失效后,方能更新。 
  -l  锁住密码,不能修改密码。仅能通过root权限操作。
  -S  列出密码的相关信息。本参数仅有系统管理者才能使用。 
  -u  解开已上锁的帐号。
  -w   在距多少天提醒用户修改密码;仅能root权限操作。

 

例1:修改用户密码:

命令:adduser

功能说明:新增用户帐号。
语  法: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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is Maintenance Mode in Linux? ExplainedWhat is Maintenance Mode in Linux? ExplainedApr 22, 2025 am 12:06 AM

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

Linux: A Deep Dive into Its Fundamental PartsLinux: A Deep Dive into Its Fundamental PartsApr 21, 2025 am 12:03 AM

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

Linux Architecture: Unveiling the 5 Basic ComponentsLinux Architecture: Unveiling the 5 Basic ComponentsApr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.