How to reset permissions for all user home dirs
Hello all,
Hope someone can help me with how best to approach this.
The home dirs permissions have been messed up by a restore of data. Users cannot log into clients for some reason. I have created a new home dir for an existing user which can now login whereas with his previous home dir could not. After checking the permissions on some home folders, it looks like the owner is missing (just blank).
I was going to use a terminal script to extract the username using dscl and then using this in a variable reset the home dirs. However, it gets a little more complicated in that the user homes are spererated into folders such as year7, year 8 etc). I have tried to extract the NFSHomeDirectory, again using dscl, but this is where I get stuck. My script allows me to pull in the first column of the array but I don't know how to edit the script to pull in the NFSHomeDirectory path into a 2nd array that can then be added to the chown script via a variable. Here is my script at the moment. $HomeDir is the variable that will hold the NFSHomeDirectory path.
#!/bin/bash
# userlist.sh
dscl /LDAPv3/127.0.0.1 -list /Users NFSHomeDirectory | awk '{print $1","$2}' > $PWD/Users.txt
UIDs=$PWD/users.txt
for name in $(awk 'BEGIN{FS=","}{print $1}' < "$UIDs" )
do
sudo chown -R $name $HomeDir
sudo chmod -R 700 $HomeDir
sudo chmod +a "$name allow list,add_file,search,delete,add_subdirectory,delete_child,readattr,writeattr,re adextattr,writeextattr,readsecurity,file_inherit,directory_inherit" $HomeDir
sudo chown -R $name:staff $HomeDir
sudo chmod -R ug+rwx $HomeDir
let "n += 1"
done
exit 0
Thanks in advance for any help.