How to Disable Shell Access for a Linux User Account?

Disable shell access for a user account
When creating a user account in Linux, the user will explicitly have shell access. This article will help you to know how to disable shell access for a Linux user account.

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.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Linux Management Services

Focus on your business, and let us take care of your Linux Servers!
From what you are reading, it seems you are interested in Linux and related technologies. If you have a moment to spare, please take a look at our Linux Management Services plan, which might interest you even more!
Linux Management Plan

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

ServerHealers uses cookies.