Friday, March 11, 2016

linux - How can I change the umask for a user when he logs on to an alternate group?



I want the umask to be more permissive for users when they switch to a non-default group. Just to demonstrate what I mean:



$ id
uid=500(beamin) gid=500(beamin) groups=10(wheel)

$ umask
0022


$ sg wheel

$ umask # I want this to now be 0002 instead
0022


I was thinking of adding a script to /etc/profile.d/ that would look like this:



if [ "`id -u`" -ge 500 ] && [ "`id -g`" -ne "`id -u`" ]; then

umask 0002
fi


I got 500 because all our user uids are larger or equal to that. Is this the best way to do it? Or does someone have something that makes more sense?


Answer



I think your solution is fine. In a shell script you can use:



(umask 022;exec sg wheel )



Test with:



umask 002
umask
( umask 022; exec sg wheel umask)
umask


For an alternative solution see my similar post: How do I set permissions structure for multiple users editing multiple sites in /var/www on Ubuntu 9.10?



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...