Reset Linux Home directory permissions based on /etc/passwd
This file contains 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 | |
chown root:root /home | |
chmod 755 /home | |
USERS=$(grep '/home' /etc/passwd | tr "\n" "\n") | |
for USER in $USERS | |
do | |
IFS=":" read -ra DETAILS <<< "$USER" | |
$(chown -R ${DETAILS[0]}:${DETAILS[0]} ${DETAILS[5]}) | |
$(chmod -R 750 ${DETAILS[5]}) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are using a custom system that has home directories elsewhere, simply substitute
/home
for your home directories directory (e.g./organisation/websites
)