search
top

Changing umask based on Group Membership in Solaris 10 in profile

Recently ran into a situation where we needed to make sure that the umask of 002 was set on all the files owned by a specific group.  There are several solutions but one way is to set the umask in the /etc/profile.

For Solaris 10 it is set in the profile here.

if [ "$LOGNAME" = "root" ]
then
PS1="ROOT@`uname -n`# " ; export PS1
else
PS1="$LOGNAME@`uname -n`$ " ; export PS1
fi
umask 022
trap  2 3

If we wanted to make all set to 002 then just modifying umask 022 would do the trick, but we want a specific group. So we add some test code after umask 022.

if [ "$LOGNAME" = "root" ]
then
PS1="ROOT@`uname -n`# " ; export PS1
else
PS1="$LOGNAME@`uname -n`$ " ; export PS1
fi
umask 022
ITEST=`id -a ${LOGNAME}|grep myspecialgrp > /dev/null;echo $?`
if [ "$ITEST" = "0" ]
then
umask 002
fi
trap  2 3

This allows us to set umask of 002 to all files created by myspecialgrp. Save the changes and login with an id in the group and touch a file and it will be set to umask 002 (rw-rw-r–).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top