Tuesday, June 9, 2015

Enable or Disable user access Linux

In Linux one user (for ex.. user named p1) is in disable mode. How to enable the user? What is the procedure?

To enable user, we should set the user to shells other than /sbin/nologin you can check available shells in file cat /etc/shells

we have changed the user shell p1 to /bin/sh. user is able to login now


usermod -s /sbin/nologin p1

[root@host-7-57 ~]# usermod -s /bin/sh p1
[root@host-7-57 ~]# su p1
sh-4.2$ bash


Disable a user

If you want user to disable . we can set the user shell to /sbin/nologin

[root@host-7-57 ~]# usermod -s /sbin/nologin p1
[root@host-7-57 ~]# su p1
This account is currently not available.-----> no allowing user to login

 
[root@host-7-57 ~]# getent passwd p1
p1:x:500:500::/home/p1:/sbin/nologin


Unlock a user 

Sometimes if user enter wrong password for 5 times, the account gets locked. You can enable it by following command.

[root@localhost ~]# passwd -u p1
Unlocking password for user p1.
passwd: Success

No comments:

Post a Comment