A bash script to automatically restore broken sudo privileges inside Distrobox containers.
If you accidentally alter permissions or get locked out of sudo with errors like sudo: /usr/bin/sudo must be owned by uid 0, this script runs from your host machine to safely bypass the container's broken environment and reset the necessary system file permissions using Podman.
podmandistroboxfzf(Optional, for an improved interactive menu)
- Create a local binary directory if it does not already exist:
mkdir -p ~/.local/bin
- Create the script file:
nano ~/.local/bin/fix-distrobox-sudo
- Paste the provided script into the file and save it.
- Make the script executable:
chmod +x ~/.local/bin/fix-distrobox-sudo
- Ensure
~/.local/binis in your system's PATH.
Run the script from your host machine (do not run it from inside the container).
To run the script and select your container from a menu, simply run the command without any arguments:
fix-distrobox-sudo
To bypass the menu and fix a specific container directly, pass the container name as an argument:
fix-distrobox-sudo my-container-name
The script forces a root shell into the target container and resets the ownership and permissions of the following critical files:
/usr/bin/sudo/usr/bin/su/etc/sudo.conf/etc/sudoers/etc/sudoers.d/