Last active
December 18, 2024 04:27
-
-
Save brunos3d/6c39b8d79e7eddd786c3cebd02da21cc to your computer and use it in GitHub Desktop.
A script to securely apply custom file and directory permissions in a user's home directory, ensuring proper access levels for sensitive files, development tools, and shared directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######### | |
##### THIS SCRIPT CAN FUCK YOUR COMPUTER, use it on your own responsibility | |
######### | |
# User directory path | |
read -p "Enter the username or press Enter to use the current user ($(logname)): " input_user | |
USER_HOME="/home/${input_user:-$(logname)}" | |
# Function to apply permissions | |
apply_permissions() { | |
chmod "$@" && return 0 || return 0 | |
} | |
echo "Applying permissions in $USER_HOME..." | |
# Apply 755 to the entire user folder as a starting point | |
apply_permissions -R 755 "$USER_HOME" | |
# Specific adjustments for important directories and files | |
apply_permissions 600 $USER_HOME/.ssh/* \ | |
"$USER_HOME/.bash_history" "$USER_HOME/.zsh_history" | |
apply_permissions 644 $USER_HOME/.ssh/*.pub "$USER_HOME/.ssh/known_hosts" \ | |
"$USER_HOME/.bashrc" "$USER_HOME/.zshrc" "$USER_HOME/.profile" | |
# Development tools | |
apply_permissions -R 775 "$USER_HOME/.npm" "$USER_HOME/.nvm" "$USER_HOME/.cache/pip" "$USER_HOME/.virtualenvs" | |
apply_permissions -R 775 "$USER_HOME/.docker" "$USER_HOME/.local/share/containers" "$USER_HOME/.config/containers" | |
apply_permissions 600 "$USER_HOME/.docker/config.json" | |
apply_permissions 644 "$USER_HOME/.gitconfig" | |
apply_permissions 600 "$USER_HOME/.git-credentials" | |
# IDEs and development tools | |
apply_permissions -R 775 "$USER_HOME/.vscode" "$USER_HOME/.idea" "$USER_HOME/.cache/Code" | |
# GnuPG | |
apply_permissions -R 600 $USER_HOME/.gnupg/* | |
apply_permissions 744 "$USER_HOME/.gnupg" | |
echo "Permissions applied successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment