Script to add users to 'user and group' of a folder and give them Read and Write permissions, in Mac

1.8k views Asked by At

Using Mac Yosemite 10.10.3

I have Jenkins installed on my mac which integrates with other applications and there is an important folder to which access should be present for all jenkins users. This can be achieved by adding them to its 'User and Group', and give them read, write access(Right click a folder/Get info/Sharing and permissions on bottom/that '+' symbol).

My question in short : To cut short, jenkins users should have access to that folder and should be present in 'User and Group' of that folder(Just as shown in the image below).

enter image description here

The above permission was given manually and I want to do that using a script which can be stored and invoked when needed.

(Am novice to shell scripting and to mac).

1

There are 1 answers

6
Bruno Lavit On BEST ANSWER

If only the jenkins user need to access this folder with a R/W access, you can use the following commands:

sudo chown -R jenkins YOUR_FOLDER (set jenkins as the folder owner)
sudo chmod -R 755 YOUR_FOLDER (jenkins will have a R/W access, read for all the other users)

Update from June 16th 2015

This is a second solution to create a group build_users, add the jenkins user to this group and update the folder permissions.

-- Create the build_users group (with the ID 3333)
sudo dscl . -create /groups/build_users PrimaryGroupID 3333

-- Add the jenkins user in this group
sudo dseditgroup -o edit -a jenkins -t user build_users

-- Make the group build_users owner of the folder
sudo chown -R :build_users my_folder

-- Give R/W permissions to the group build_users
sudo chmod -R g=rw my_folder