Way 1 : Move the user into /sbin/nologin shell
syntax : usermod username -s /sbin/nologin
[root@localhost ~] # usermod test -s /sbin/nologin
[root@localhost ~] # su test
This account is currently not available.
Way 2 : lock the user using passwd and usermod commands
syntax : passwd --lock username or usermod --lock username
[root@localhost ~]# passwd --lock test
Locking password for user test.
passwd: Success
[root@localhost ~]# su gugu
[gugu@localhost ~]$ su test # login to blocked user from normal user
Password:
su: Authentication failure
or [root@localhost ~]# usermod --lock test
[root@localhost ~]# su gugu
[gugu@localhost ~]$ su test # login to blocked user from normal user
Password:
su: Authentication failure
syntax : usermod username -s /sbin/nologin
[root@localhost ~] # usermod test -s /sbin/nologin
[root@localhost ~] # su test
This account is currently not available.
Way 2 : lock the user using passwd and usermod commands
syntax : passwd --lock username or usermod --lock username
[root@localhost ~]# passwd --lock test
Locking password for user test.
passwd: Success
[root@localhost ~]# su gugu
[gugu@localhost ~]$ su test # login to blocked user from normal user
Password:
su: Authentication failure
or [root@localhost ~]# usermod --lock test
[root@localhost ~]# su gugu
[gugu@localhost ~]$ su test # login to blocked user from normal user
Password:
su: Authentication failure