Tags

, , , ,

user and group management in linux

hi readers i am back with informative Linux article. This article is dedicated to those readers who are new to linux and are beginner in this field. Today i am going to share a basic article on how to manage users and groups in Linux.

If you are absolute beginner and do not have much knowledge about user and group management in Linux then after reading this tutorial you got enough knowledge to manage groups and users in a Linux machine.

Note:-> All commands used in this tutorial are valid for Rhel4/5/6/7 ,centOs4/5/6/7 and Fedora.

 User management in Linux

Under user management we will learn ==>

How to create a user in Linux?

how to delete a user in Linux?

how to disable a user in Linux?

how to enable a user in Linux?

how to delete password of the user?

how to lock a user in Linux?

how to unlock a user in Linux?

How to add a user in Linux?

Adding a user in linux is very simple. follow simple steps to add a user in linux

Step 1> keep in mind that you are logged in on your linux machine as a root user because only root can add or remove users.

Step 2> now use below command to add a user ==>

#useradd xyz

userinlinux

Step 3> now its time to give password to the user ==>

#passwd xyz

user

How to check details of added user ==>

#cat /etc/passwd

user3

The output of above command is shown below

xyz:x:1004:1004::/home/xyz:/bin/bash

user4

Now i will explain every field of above line==>

xyz–> Name of the user
x–> password of user(encrypted)
1004–> User id (UID)-user identification number
1004–> Group id(GID)-is the primary group id.found in the /etc/group file
::–> Comment or description
/home/xyz–> Home directory of the user
/bin/bash–> shell where the program is written.

How to view password related information of  users ==>

#cat  /etc/shadow

shadow

Output ==>

shadow2

here password in shown in encrypted form.

How to change password of user ==> 
To change the password of a user xyz just use below command ==>
#passwd xyz

user
Now it will ask for the new password, simply input your new password.

How to delete password of user==>
If you forgot the user password then a root user had a option to remove the password of exiting user==>

#password -d xyz

delpass
Now when you login with user xyz then it will login directly without asking password.

How to delete a user in Linux

To delete a user in linux you have to use userdel command as shown below==>

#userdel xyz

user5

Till now we have learned how to add and delete a user, now its time to disable and enable a user.

How to disable a user ==>

If you want to disable a user then use below command

user6

#usermod -s /sbin/nologin <user name>
for e.g. ==> #usermod -s /sbin/nologin xyz
here sbin => a directory which contains system binary files
nologin => this file is responsible to disable a user

How to enable a user ==>

If you want to enable a user then use below command==>

user7

#usermod -s /bin/bash <user name>
or
#usermod -s /bin/ksh <user name>
for e.g.

#usermod -s /bin/bash xyz

User locking and unlocking in Linux

Method (1)

To lock the user ==>

A locked user can’t login in a Linux system till the root of that Linux system unlock it.

#passwd -l xyz

userlock
here l= lock

To unlock the user ==>

#passwd -u xyz

userunlock
here u = unlock

Method (2).

To lock the user==>

#usermod -p “*” <user name>
for e.g. #usermod -p “*” xyz

newlock

To unlock the user ==>

#passwd xyz

user

 

Read also ==>

|| best and easy to configure yum server in Linux??

|| Telnet server configuration in Linux ??

|| Complete tutorial on SSH server configuration in Rhel5/Rhel6.

Group management in Linux

Under group management we will learn how to create, delete,and how to add users in a group. ==>

Group creation and deletion in Linux.

Command to add a new group in linux ==>

#groupadd <group name>

for e.g. #groupadd school

grouipadd school

how to view status of groups in Linux ==>

To see how many groups are there on your Linux machine use below command ==>

#cat /etc/group

group2

output ==>

school:x:1005:xyz

usraddingp2

Now let me explain the output of above command ==>

school–> group name
x–> password
1005–> group id
xyz–> group members or users that are added in the group

How To delete or remove the existing group–>

#groupdel <group name>

#groupdel school

grpdel

How To Add a user in a Group–>

Suppose you have created a user with name xyz and now you have to move this user to the group SCHOOL, then you have to use below command ==>

#usermod -G <group name> <user name>

#usermod -G school xyz

adduseringp

here G= group

In the 2nd part of this tutorial we will learn some advance stuff related to user and group management in Linux. Stay updated and give your feedback if you like his article.