So for the past few days I've been working on a new Cent7 server to replace an aged 6.6 vm. This box sits in the DMZ and is used by various entities around the state to sftp certain txt files to. So there are roughly 50 home directories.. each with sub folders and an ssh key. So in an effort to *not* force the users to create new ssh keys I rsync'd the entire parent folder over. First time I lacked the proper permissions and wound up creating the home folders but nothing underneath.
So long story short, I eventually was able to get the correct syntax down to rsync the /chroot/parent and all the individual home sub-folders to the new server WITH the two sub folders and the .ssh(which houses the authorized_key file). EUREKA!
However now all the permissions were borked up. My own local ssh user had taken ownership of the parents, and children in both user and group. DOH! I was able to clean up the group side of things easily enough via: 'chown -R :group /*' However the user side was trickier because the user side on the two sub folders needed to be owned by the user in question. (Obviously) but luckily enough for me the home folder's names was the username entirely. Lucked into this absolute gem:
Fix the path in Line 1, and you are golden!
for dir in /home/*/; do
# strip trailing slash
homedir="${dir%/}"
# strip all chars up to and including the last slash
username="${homedir##*/}"
case $username in
*.*) continue ;; # skip name with a dot in it
esac
chown -R "$username" "$dir"
done
No comments:
Post a Comment