Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

Friday, March 10, 2017

BASH: change ownership of subfolders based on parent folder name

Sounds convoluted, and honestly I felt overwhelmed trying to figure out how to handle this programmatically.

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

Friday, September 26, 2014

Quick easy way to determine if your *nix system is vulnerable to Shellshock

Run this command from your terminal:

x='() { :;}; echo VULNERABLE' bash -c :

Systems that are vulnerable will return:

$ x='() { :;}; echo VULNERABLE' bash -c :
VULNERABLE

Systems that have been patched will return:

$ x='() { :;}; echo VULNERABLE' bash -c :
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'

For an in depth analysis and explanation go here: http://security.stackexchange.com/questions/68168/is-there-a-short-command-to-test-if-my-server-is-secure-against-the-shellshock-b

This guy does a much better job than I could ever hope to.