Search code examples
linuxbashshellselinux

Creating a Bash Script to Check and Disable SE Linux: How to Prompt User Input?


How do I create a bash script that prompts the user to check if SE Linux is enabled on their machine, and if it is, requests them to execute a script to disable it?


Solution

  • ENABLED=`cat /selinux/enforce`
    if [ "$ENABLED" == 1 ]; then
      echo "SELinux is enabled, disable? (yes/no):"
      read disable
      if [ $disable == "yes" ]; then
        echo "disabling selinux"
        setenforce 0
      fi
    fi
    

    This script should be run as root, or with permission to do the following:

    cat /selinux/enforce
    setenforce 0