xGuard is a wrapper for the native rm utility designed to protect system directories and critical files from accidental deletion. It monitors specified directories and restricts deletion within a defined depth level.
xGuard operates only in interactive sessions, ensuring that applications and services can still use the native rm utility without interference.
Follow these steps to install xGuard:
-
Download and extract the script
-
Locate the native rm utility
which rm
-
Edit the xGuard/rm script and configure the following:
- Add any additional directories to the protected list.
- Set your password.
- Specify the path to the native rm utility.
-
Modify the .bashrc file of the user that xGuard should apply to by adding the xGuard path:
export PATH="/path/to/xGuard:$PATH"
export PATH="/home/essien/myScripts/xGuard:$PATH"
-
Save the file
-
Reload the .bashrc file
source .bashrc -
Verify that rm points to xGuard:
which rm
The output should show the xGuard rm utility path, e.g.: /home/essien/myScripts/xGuard/rm instead of native rm utility path.
After installation, xGuard functions similarly to the native rm utility. However, when attempting to delete a protected file or directory within the defined depth level, you will be prompted to enter the configured password.
- If authentication is successful, the deletion proceeds.
- When deleting a directory or multiple files, xGuard will prompt for approval of all items after successful authentication. If not approved, each protected file will require individual password confirmation.
- To bypass xGuard and use the native rm utility, specify the absolute path of the native rm utility