0% found this document useful (0 votes)
2 views

Linux User Account command

Uploaded by

yarzarayeko970
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Linux User Account command

Uploaded by

yarzarayeko970
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Linux User Account command

--------------------------------------------

When we run ‘useradd‘ command in Linux terminal, it performs following major things:

It edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created User account.

Creates and populate a home directory for the new user.

Sets permissions and ownerships to home directory.

Basic syntax of command is:

#useradd [options] username

1. How to Add a New User in Linux

[root@loop ~]# useradd nanda

[root@loop ~]# passwd nanda


Changing password for user nanda.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

<OR>

[root@loop ~]# useradd nanda; echo -e "yngWIE500\nyngWIE500" | passwd nanda

Note : Once a new user created, it’s entry automatically added to the ‘/etc/passwd‘ file.
The file is used to store users information and the entry should be.

nanda:x:504:504:nanda:/home/nanda:/bin/bash

The above entry contains a set of seven colon-separated fields, each field has it’s own meaning.
Let’s see what are these fields:
Username : User login name used to login into system. It should be between 1 to 32 charcters long.

Password : User password (or x character) stored in /etc/shadow file in encrypted format.

User ID (UID) : Every user must have a User ID (UID) User Identification Number.
By default UID 0 is reserved for root user and UID’s ranging from 1-99 are reserved for
other predefined accounts. Further UID’s ranging from 100-999 are reserved for system
accounts and groups.

Group ID (GID) : The primary Group ID (GID) Group Identification Number stored in /etc/group file.

User Info : This field is optional and allow you to define extra information about the user.
For example, user full name.This field is filled by ‘finger’ command.

Home Directory: The absolute location of user’s home directory.

Shell : The absolute location of a user’s shell i.e. /bin/bash.


2. Create a User with Different Home Directory

[root@loop ~]# useradd -d /opt/la-home lauser

[root@loop ~]# cat /etc/passwd | grep lauser

lauser:x:505:505::/opt/la-home:/bin/bash

3. Create a User with Specific User ID

[root@loop ~]# useradd -u 999 mgmg

[root@loop ~]# cat /etc/passwd | grep mgmg

mgmg:x:999:999::/home/mgmg:/bin/bash

4. Create a User with Specific Group ID

[root@loop ~]# useradd -u 1000 -g 500 susu

[root@loop ~]# cat /etc/passwd | grep susu

susu:x:1000:500::/home/susu:/bin/bash

5. Add a User to Multiple Groups

[root@loop ~]# useradd -G adminsgrp,salesgrp,webgrp susu

[root@loop ~]# id susu

uid=1001(susu) gid=1001(susu) groups=1001(susu) , 500(adminsgrp) , 501(salesgrp) , 502(webgrp)

6. Create a User with Account Expiry Date

[root@loop ~]# useradd -e 2014-03-27 user02

[root@loop ~]# chage -l user02

Last password change : Mar 28, 2014


Password expires : never
Password inactive : never
Account expires : Mar 27, 2014
Minimum number of days between password change :0
Maximum number of days between password change : 99999
Number of days of warning before password expires :7

7. Create a User with Password Expiry Date

[root@loop ~]# useradd -e 2014-03-27 -f 45 user02

Note : Set a account password expiry date i.e. 45 days on a user ‘user02’ using ‘-e‘ and ‘-f‘ options.

You might also like