Locking and Unlocking user in linux
In this post we will learn about how to lock and unlock user
account in linux. With the help of two commands you can lock and unlock the
user account in linux. We will also know, how to find the user account has lock
and unlock status.
After creating a user to modify the attributes of user like
changing Uid, changing Secondary group id or adding a comment or sometimes it’s
required to lock user account so that he can not login to the machine. This is
done for security reasons so that unauthorized users are not allowed to login.
Locking user account can be done by following two commands.
To Lock the user
account in Linux,use the given below command
We have two options to use any of the given below command to
lock the user account in linux
By Using Passwd
command
Syntax : #passwd –l <username>
#passwd -l username
[root@linuxelearn ~]# passwd -l rahul
Locking password for user rahul.
passwd: Success
[root@linuxelearn ~]#
[root@linuxelearn ~]# tail /etc/shadow
rpcuser:!!:17026::::::
nfsnobody:!!:17026::::::
pulse:!!:17026::::::
gdm:!!:17026::::::
sshd:!!:17026::::::
tcpdump:!!:17026::::::
user:$6$kYw9IHnXahbyylyd$.fMwQf.WnzN7ftRawlOYPHAXsYZ3JvfOjawESWYBA8sWv413yfqqfWcdGXOcPoN6PFyXUmrh452c4XS2chJj30:17026:0:99999:7:::
rahul:!!$6$IfqyPCtQ$v5275VCBDdM5iecTfWBVvs4gOClXyEiauVHS7Aa9861cpwo3GKAQnyYuNdK4O85Pr9QS8HW5fJvTUn9pCGWhg1:17027:0:99999:7:::
nagios:$6$9YMaBpCe$U4puQbI98S.epxe21aiwOnpTBLEYl/jfAXfdkUzIEw75Cw/WIvGAt254QiBEBf3lZ6niwAJJwAFyf6u/XAEso1:17037:2:7:1:0:17040:
pooja:$6$SM3See4e$Yk1lSTk8G09zvrIYZv0W13hIolfQSQyyyTt5RT35nNqVpDft3hmegQN9p9.nd1rig/9VgolhNNlNgsk.Bz3Q5/:17153:0:99999:7:::
[root@linuxelearn ~]#
|
In above example after locking the user account by using
passwd command. The double exclamation(!!) sign after username called rahul
confirmed the account is locked.
OR
By using usermod
command
Syntax : # usermod <options>
<username>
Options are:
All the options which are used with useradd command can be
used and also the following,
- -l To change login name
- -L To LOCK account
- -U To UNLOCK account
- Ex #usermod -l newname oldname
- Ex #usermod –L username
- Ex #usermod –U username
Note: - When an
account is locked it will show ! (Exclamation mark) in /etc/shadow file.
Locking a user
account:
To lock a user account use the following
#usermod –l rahul
And verify it in /etc/shadow
file, it shows exclamation mark before user account or try login as rahul
[root@linuxelearn ~]# usermod -L rahul
[root@linuxelearn ~]# tail /etc/shadow
rpcuser:!!:17026::::::
nfsnobody:!!:17026::::::
pulse:!!:17026::::::
gdm:!!:17026::::::
sshd:!!:17026::::::
tcpdump:!!:17026::::::
user:$6$kYw9IHnXahbyylyd$.fMwQf.WnzN7ftRawlOYPHAXsYZ3JvfOjawESWYBA8sWv413yfqqfWcdGXOcPoN6PFyXUmrh452c4XS2chJj30:17026:0:99999:7:::
rahul:!$6$IfqyPCtQ$v5275VCBDdM5iecTfWBVvs4gOClXyEiauVHS7Aa9861cpwo3GKAQnyYuNdK4O85Pr9QS8HW5fJvTUn9pCGWhg1:17027:0:99999:7:::
nagios:$6$9YMaBpCe$U4puQbI98S.epxe21aiwOnpTBLEYl/jfAXfdkUzIEw75Cw/WIvGAt254QiBEBf3lZ6niwAJJwAFyf6u/XAEso1:17037:2:7:1:0:17040:
pooja:$6$SM3See4e$Yk1lSTk8G09zvrIYZv0W13hIolfQSQyyyTt5RT35nNqVpDft3hmegQN9p9.nd1rig/9VgolhNNlNgsk.Bz3Q5/:17153:0:99999:7:::
[root@linuxelearn ~]#
|
In the above example after locking the user account by using
usermod command. The single exclamation(!) sign after username called rahul
,confirmed the account is locked.
Note: if user
passwd is not set and if we use usermod command to lock the account,it will
show double exclamation sign
Unlocking a user
account:
Unlock the above account
#passwd –u
<username>
#passwd –u rahul
[root@linuxelearn ~]# passwd -u rahul
Unlocking password for user rahul.
passwd: Success
[root@linuxelearn ~]#
|
#usermod -U rahul
Ans verify it in /etc/shadow
file, it shows exclamation mark before user account or try login as rahul
[root@linuxelearn ~]# usermod -U rahul
[root@linuxelearn ~]# tail /etc/shadow
rpcuser:!!:17026::::::
nfsnobody:!!:17026::::::
pulse:!!:17026::::::
gdm:!!:17026::::::
sshd:!!:17026::::::
tcpdump:!!:17026::::::
user:$6$kYw9IHnXahbyylyd$.fMwQf.WnzN7ftRawlOYPHAXsYZ3JvfOjawESWYBA8sWv413yfqqfWcdGXOcPoN6PFyXUmrh452c4XS2chJj30:17026:0:99999:7:::
rahul:$6$IfqyPCtQ$v5275VCBDdM5iecTfWBVvs4gOClXyEiauVHS7Aa9861cpwo3GKAQnyYuNdK4O85Pr9QS8HW5fJvTUn9pCGWhg1:17027:0:99999:7:::
nagios:$6$9YMaBpCe$U4puQbI98S.epxe21aiwOnpTBLEYl/jfAXfdkUzIEw75Cw/WIvGAt254QiBEBf3lZ6niwAJJwAFyf6u/XAEso1:17037:2:7:1:0:17040:
pooja:$6$SM3See4e$Yk1lSTk8G09zvrIYZv0W13hIolfQSQyyyTt5RT35nNqVpDft3hmegQN9p9.nd1rig/9VgolhNNlNgsk.Bz3Q5/:17153:0:99999:7:::
[root@linuxelearn ~]#
|
Observe in both
pictures that once the account is unlocked the exclamation is gone.
You Must Have To Read This....
- Linux interview question and answers..
- How to Change Permission of Files and Directories in Unix/Linux
- What is the filesystem in linux ~ Unix and Linux Filesystem in detail Hierarchy system
- How to Update newly created partition – How to Formatting a partition with file system
Please Comment if you like the post and If you have any Suggestion also......
1 comments:
It is very useful and good described..
ReplyKeep it up...
Post a Comment