Skip to content

Instantly share code, notes, and snippets.

@Loopshape
Last active March 10, 2024 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loopshape/51ad2be74ebc1c2b68e61c6b7a696416 to your computer and use it in GitHub Desktop.
Save Loopshape/51ad2be74ebc1c2b68e61c6b7a696416 to your computer and use it in GitHub Desktop.
DEBIAN LINUX // DISTRO REPAIR :: Permissions (global) by LOOPCORE feat. OpenAI
#!/bin/bash
echo "DEBIAN LINUX // DISTRO REPAIR by LOOPCORE feat. OpenAI"
echo "(Use with caution!!! Success may not be guaranteed...)"
# Check if script is run as root or with elevated privileges
if [ "$(id -u)" != "0" ]; then
echo "Unsuccessful or impossible structures were found and critical damaged!!!"
exit 1
fi
# Change the FileBit-Mask for Operation
umask=022
# Function to recursively correct ownership and permissions
correct_permissions() {
local dir="$1"
local user="$2"
local group="$3"
# Correct ownership recursively
chown -R $user:$group "$dir"
# Correct permissions recursively for files
find "$dir" -type f -exec -R chmod 644 {} \;
# Correct permissions recursively for directories
find "$dir" -type d -exec -R chmod 755 {} \;
}
# Set the desired user and group
desired_user="root"
desired_group="root"
# Function to detect and deactivate duplicate Apt source entries
remove_duplicate_sources() {
duplicates=$(grep -E -o '^deb.*' /etc/apt/sources.list /etc/apt/sources.list.d/* | sort | uniq -d)
if [ ! -z "$duplicates" ]; then
echo "Duplicate Apt source entries detected:"
echo "$duplicates"
echo "Deactivating the duplicate entries..."
echo "$duplicates" | while read line; do
sudo sed -i "/$line/s/^/#/" /etc/apt/sources.list /etc/apt/sources.list.d/*
done
else
echo "No duplicate Apt source entries found."
fi
}
# Function to clean dpkg-package and apt referencing
clean_references() {
echo '#!/bin/true' > /usr/bin/start-stop-daemon
chmod +x /usr/bin/start-stop-daemon
}
# Function to repair man cache permissions
repair_man_cache() {
sudo chown -R man:man /var/cache/man/
sudo chmod -R 755 /var/cache/man/
}
# Perform root directory permission scan and correction
root_dir="/"
correct_permissions "$root_dir" "$desired_user" "$desired_group"
# Perform repairs and optimizations
remove_duplicate_sources
clean_references
repair_man_cache
# Additional commands for repairing access
sudo chmod 666 /dev/null
sudo chown -R root:root /usr/bin/su* && sudo chmod -R 4755 /usr/bin/su*
sudo chown root:root /etc/sudoers
sudo chmod -R u=rwX,go=rX /
sudo chmod -R 755 /bin
sudo chmod -R 755 /boot
sudo chmod -R 755 /dev
sudo chmod -R 755 /etc
sudo chmod -R 755 /home
sudo chmod -R 777 /initrd.img*
sudo chmod -R 755 /lib
sudo chmod -R 755 /lib64
sudo chmod -R 700 /lost+found
sudo chmod -R 755 /media
sudo chmod -R 755 /mnt
sudo chmod -R 755 /opt
sudo chmod -R 555 /proc
sudo chmod -R 700 /root
sudo chmod -R 755 /run
sudo chmod -R 755 /sbin
sudo chmod -R 755 /srv
sudo chmod -R 555 /sys
sudo chmod -R 1777 /tmp
sudo chmod -R 755 /usr
sudo chmod -R 755 /var
sudo chmod -R 777 /vmlinuz*
# Validate permissions for sudo command
sudo -l
# Harden SSH configuration
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart sshd
echo "Task completed :: Reboot Machine for a CleanRestart, now!"
@Loopshape
Copy link
Author

This script includes functions to scan for permission errors in the root directory and subdirectories, as well as checking permissions for sudo, ssh, apt, and dpkg references. Additionally, it executes the provided clean dpkg-package and apt referencing code. As always, exercise caution when running such scripts on production systems and ensure thorough testing in a controlled environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment