Skip to content

Instantly share code, notes, and snippets.

@willpower232
Created December 13, 2017 16:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save willpower232/08aa6cbaec1d4ee77de4e415bd0e77a8 to your computer and use it in GitHub Desktop.
Reset Linux Home directory permissions based on /etc/passwd
#!/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
@willpower232
Copy link
Author

If you are using a custom system that has home directories elsewhere, simply substitute /home for your home directories directory (e.g. /organisation/websites)

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