What if there are other users in your system that have shell access to your system? Follow the steps given below to find them and disable shell access.
Run the below command to list all users that have shell access to your system.
grep bin/bash$ /etc/passwdroot:x:0:0:root:/root:/bin/bash mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash test2:x:10002:10002::/home/test2:/bin/bash hduser:x:10003:10003::/home/hduser:/bin/bash admin:x:10004:10004::/home/admin:/bin/bash boot:x:0:0:root:/root:/bin/bash sshusr:x:10006:10006::/home/sshusr:/bin/bash u1:x:10007:10007::/home/u1:/bin/bash
If you find any unknown users in this list, change that user’s shell to /sbin/nologin by running the below command.
Here I’m going to change the shell of “u1″ user to /sbin/nologin”.
chsh u1 Changing shell for u1. New shell [/bin/bash]: /sbin/nologin Shell changed.
Well, this is Linux, and there must be many other ways to do something. In this case, there are different ways to do this other than using the “chsh” command. You can directly edit the /etc/passwd file and change a user’s shell to “nolongin. ” You can also use “usermod -s” just like the example given below.
usermod -s /sbin/nologin u1
So this is how you can change the shell of a user.