Linux: How To Create User Account Using Useradd Command

You’ll how to crate a user account in linux operation system, how to change the default information for new users.

In linux, you can use useradd command to create a new user accout, of course, you need login the system as root user so that you have enough permission to create new user. when you created a new user, system will update “/etc/passwd“, /etc/group” , “ /etc/shadow” files for newly created user account and also will create user’s home directory and also set permission and ownshps to user’s home directory for

​The syntax is as followss:

useradd [options] <username>

1. Create A New User In Linux

To create a new user account,  you can use useradd command with a new username, type the following command :

#useradd atest

it will create a new user named as “atest”. now you can open “/etc/passwd” file, a new line will be added into it.

Set a password for atest user using following command:

#passwd atest

2. Create A User With A Particular User ID

you know each user have a unique identification number(UID), system will assign a certain uid number to user, but if you want to specify your owned uid number for user you will create. then use useradd command pass “-u” option and your uid number. see below sample:

[root@devops ~]# useradd -u 800 btest

[root@devops ~]# id btest

uid=800(btest) gid=800(btest) groups=800(btest)

3. Create A User With A Particular Group ID

Issue the useradd command with “-g” option, type the below command:

#useradd -g 600 atest

it will create a new user atest and it’s primary group id is 600.

4. Set User Account Expiry Date

you can user option “-e” to set user account expiry date, the “-e” option is used to set the date, in YYYY-MM-DD format, on which the new account will automatically expire. This is useful for creating temporary accounts and for dealing with the tendency of busy system administrators to forget to delete them, which can become a security risk.

Set user “atest” expiry date to “2018-10-16”, issue the following command:

#useradd -e  2018-10-16 atest

If you do not specified expiry date, useradd will use the default expiry date specified by the EXPIRE variable in /etc/default/useradd, or an empty string (no expiry) by default.

5. Set User Password Expiry Date

Also you can set the expiry date for user’s password through using “-f” option , The -f option is used to specify the number of days after a password expires until the account is permanently disabled see below sample:

#useradd -f  30 atest

it will set default password expiry date of user “atest” to 30days.

Done…

You might also like:

Sidebar



back to top