How to Fix /bin/bash permission denied after Enabling SELinux

Please Subscribe to our YouTube Channel

Earlier we talked about how you can enable SELinux on Linux Servers, but if you have not followed that instruction properly or used the incomplete instruction published somewhere else, then you may have ended up break your system. Breaking doesn’t mean here, your websites hosted there will stop working. It will still work, but you cannot log in to the Terminal or SSH. You will always get this error /bin/bash permission denied.

Two Ways to Fix the Issue

Method 1: Disable SELinux first: How will you do that?

If you have already hosted the websites or have some kind of control panel installed, then it’s easy to fix. Follow the instruction below:

  • Go to the root folder then go to /etc/selinux/config
  • Edit the config file and type disabled as shown in the screenshot below
disable SELinux
  • Save the file
  • Reboot the server. Since you don’t have access to terminal, you can reboot from the control panel or from the hosting panel.
  • Once rebooted, you will be able to access the terminal if you want to recheck
  • Now, go to that folder again /etc/selinux/config
  • Edit the config file and replace disabled with enforcing
SeLnix
  • Now log in to Terminal or SSH and type sudo touch /.autorelabel (We have already explained here why you need this)
  • Now type sudo reboot
  • It will reboot the server but will take longer than the usual reboot. So have some patience
  • Once rebooted, you can access the terminal/ssh. No more error!

Method 2:

If you don’t have any kind of Control Panel Installed to access files and folders. The only option is to reinstall the Operating System. However, if you don’t have any control panel installed, it’s most likely you don’t have any website hosted there (not necessarily). If you have, you can take the website back, but that would be without doing a thing on Control Panel. If you are using WordPress sites, there are plug-ins like Total Upkeep, BackUp Buddy, etc., that can help you take website backup along with databases.