Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add users under Linux

Shulou Source: shulou.com Published: 2022-06-01 16:01:05 09月12日 Update

This article is about how to add users under Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The useradd or adduser command is used to set up a user account and create a starting directory for the user, and the permission is superuser.

Syntax:

Useradd [parameters] name

Parameters:

-c: add the comment text, which is saved in the remarks column of passwd. -d:-home-dir HOME_DIR specifies the home directory-e: specifies the expiration date of the account. The date format is MM/DD/YY, for example, 06ly30and12. The default means permanent. -f: specify how many days after the password expires to close the account. If the account is 0, it is disabled immediately; if it is-1, the account is always available. The default value is-1. -g:-gid GROUP specifies gid-G: specifies the additional group to which the user belongs. -l: do not add users to lastlog and failog, this user's login record does not need to be recorded.-m: automatically establish the user's login directory. -M: do not automatically create a user's login directory. -n: cancels the establishment of a group with the user name. -p:-password PASSWORD specifies the password of the new user-r:-system establishes a system account-s: specifies the shell to be used by the user after login. The default is / bin/bash. -u: specify the user ID number. This value must be unique in the system. 0room499 is reserved for system user accounts by default, so the value must be greater than 499.

Examples of usage:

Non-root users need to temporarily adjust their permissions to execute useradd, preceded by sudo

Add a new user: user1

Under root:

Useradd user1

Other users:

Sudo useradd user1

View a list of linux users:

Cat / etc/passwd

Add a new user: user2 and specify a user group: ftp

Under root:

Useradd-g ftp user2

Add a new user: user4 and specify the home directory: / mnt/bak/

Under root:

Useradd-d / mnt/back/ user4

If there is no such directory, an error will be reported, and you will need to create the directory manually.

You need to change to create a directory under root, and login will be normal after creation. (you can also create sudo rights)

Add a new user: user5 and set the password to 123456

Under root:

Useradd-p 123456 user5

View the linux user password:

Cat / etc/shadow

Add a new FTP user: ftp2018 (no need to log in to the system)

Under root:

Useradd-g ftp-s / sbin/nologin ftp2018

Complete syntax: adduser [- c comment] [- d home_dir] [- e expire_date] [- f inactive_time] [- g initial_group] [- G group [, …]] [- m [- k skeleton_dir] |-M] [- p passwd] [- s shell] [- u uid [- o]] [- n] [- r] loginid

Thank you for reading! This is the end of the article on "how to add users under Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: User directory account password system remarks login content parameters text date more permissions articles grammar account good practical valid command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Shulou Tech Info Shulou Information MariaDB