Script to remove AppArmor from Ubuntu 22.04


#!/bin/bash

# Stop AppArmor service
echo "Stopping AppArmor service..."
sudo systemctl stop apparmor
sudo systemctl disable apparmor

# Remove AppArmor profiles
echo "Removing AppArmor profiles..."
sudo rm -rf /etc/apparmor.d/

# Uninstall AppArmor packages
echo "Uninstalling AppArmor..."
sudo apt purge apparmor apparmor-utils -y

# Check AppArmor status
echo "Checking AppArmor status..."
if command -v aa-status &>/dev/null; then
    aa-status
else
    echo "AppArmor is not installed or no longer active."
fi

# Update GRUB configuration if needed
echo "Updating GRUB configuration..."
sudo sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/s/ \?apparmor=[^ ]*//g' /etc/default/grub
sudo update-grub

# Reboot system
echo "Rebooting system..."
sudo reboot

How to use this script:

Save the script to a file, for example, remove_apparmor.sh.
Make it executable:

chmod +x remove_apparmor.sh

Run the script with sudo:

sudo ./remove_apparmor.sh

Previous Next