USER AND GROUP MANAGEMENT IN LINUX PART 1

In this post we will learn how to add user , assign password to user , delete password to user , list of users in your system , add group , add user in group  , check group , removing user from group , create multiple user and giving password to them , check user accounts having empty password , lock user , setting expiry date for any user and many more .

HOW TO ADD USER IN LINUX

Just type useradd command then  username you want to add.

[root@localhost ~]# useradd deepit
[root@localhost ~]# useradd deepit1
[root@localhost ~]# useradd deepit2

HOW TO ASSIGN PASSWORD TO USER

To assign password to user type passwd then name of user .

It will ask for password two times to check . After giving password user can login with that password .

[root@localhost ~]# passwd deepit
Changing password for user deepit.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd deepit1
Changing password for user deepit1.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

HOW TO DELETE PASSWORD OF ANY USER

With this command passwd -d username , it will delete password of username .

When that user try to login linux won’t ask for password .

[root@localhost ~]# passwd -d deepit
Removing password for user deepit.
passwd: Success
[root@localhost ~]# passwd -d deepit1
Removing password for user deepit1.
passwd: Success
[root@localhost ~]# passwd -d deepit2
Removing password for user deepit2.
passwd: Success

HOW TO CHECK USERS IN YOUR MACHINE

/home is a path where all users data are stored .

[root@localhost ~]# cd /home
[root@localhost home]# ls
d  d1  d2  d3  D6  D7  D8  deepit  deepit1  deepit2

FOR CREATING TOO MANY USERS

Type below command to make multiple users

After echo, deepit is password for user a1 ,a2 ,a3

[root@localhost home]# for USER in a1 a2 a3
> do
> useradd $USER
> echo deepit |passwd --stdin $USER
> done
useradd: user a1 exists
Changing password for user a1.
passwd: all authentication tokens updated successfully.
useradd: user a2 exists
Changing password for user a2.
passwd: all authentication tokens updated successfully.
useradd: user a3 exists
Changing password for user a3.
passwd: all authentication tokens updated successfully.

FOR PASSWORD STATUS OF ANY USER

[root@localhost home]# passwd -S deepit
deepit NP 2017-01-13 0 99999 7 -1 (Empty password.)

SET EXPIRY DATE FOR ANY USER (DAYS)

In this command user id will be expired after 22 days .

[root@localhost home]# chage -M 22 deepit

SET EXPIRY DATE FOR ANY USER (DATE/MONTH/YEAR )

In this command user id will be expired after specific date .

[root@localhost home]# chage -E "2017-02-20" deepit

TO LIST USER’S PASSWORD RELATED DETAILS

[root@localhost home]# chage --list deepit
Last password change                                    : Jan 14, 2017
Password expires                                        : Feb 05, 2017
Password inactive                                       : never
Account expires                                         : Feb 20, 2017
Minimum number of days between password change          : 0
Maximum number of days between password change          : 22
Number of days of warning before password expires       : 7

TO LOCK USER AFTER CERTAIN NO.OF DAYS

[root@localhost ~]# chage -I 50 deepit

TO CHECK USER ACCOUNT HAVING EMPTY PASSWORD

[root@localhost home]# awk -F: '($2==""){print}' /etc/shadow
d2::17179:0:99999:7:::
d3::17179:0:99999:7:::
deepit::17180:0:22:7::17217:
deepit1::17180:0:99999:7:::
deepit2::17180:0:99999:7:::

TO LOCK EMPTY PASSWORD

[root@localhost home]# passwd -l deepit
Locking password for user deepit.
passwd: Success

TO CHECK GROUP

Below will show how many group you have in your system

[root@localhost ~]# cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
deepit:x:511:
deepit1:x:512:

TO ADD GROUP

[root@localhost ~]# groupadd 3usageeks

TO ADD USER IN GROUP

[root@localhost ~]# usermod -G 3usageeks deepit

TO REMOVE USER FROM GROUP

[root@localhost ~]# gpasswd -d deepit 3usageeks
Removing user deepit from group 3usageeks

TO SEE USER DATABASE

To see the list of users and it’s related information like user name,user id,group id, user extra information,user home directory and shell used by users.

[root@localhost ~]# cat /etc/passwd
d:x:502:502::/home/d:/bin/bash
e:x:503:503::/home/e:/bin/bash
f:x:504:504::/home/f:/bin/bash
d1:x:505:505::/home/d1:/bin/bash
d2:x:506:506::/home/d2:/bin/bash
d3:x:507:507::/home/d3:/bin/bash
D6:x:508:508::/home/D6:/bin/bash
D7:x:509:509::/home/D7:/bin/bash
D8:x:510:510::/home/D8:/bin/bash

Don’t hesitate to comment if you got any problem in running above commands .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s