How do you change a user's primary group as they change directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whir
    New Member
    • Feb 2009
    • 1

    How do you change a user's primary group as they change directory

    User1 is a member of Group1, Group2 and Group3, each group has a directory (say /home/group1, /home/group2, ...)

    How do I make it so that when User1 cds to /home/group1, their primary group becomes group1, when they cd to group2 they become group2, etc?

    Essentially, I'm only looking to do this so that when User1 makes a new file in each respective directory, it can be set group writable for the appropriate group.

    I will be doing this on Solaris 10 (Although I am testing on Ubuntu 8.10...)

    Thanks!
  • kaarthikeyapreyan
    New Member
    • Apr 2007
    • 106

    #2
    try cron

    I suggest that u set up a cron that updates the permission once a file is created or check for any new file in the corresponding directory and update its permissions.

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Another option would be to overload the cd command with a local script, so that if checks if the directory that it's changing to is in one of these places and if so change the default group.

      Greetings,
      Nepomuk

      Comment

      • kvmreddy
        New Member
        • Mar 2010
        • 2

        #4
        Change group owner ship of each directory first, then add setgid bit on each
        directory. setgid allows to inherit parent directory GID, when file or
        directory created in that directory. To know mor about setgid, setuid
        check bellow link.
        Advanced Linux/UNIX file permissions

        Comment

        • ennoil
          New Member
          • May 2010
          • 11

          #5
          To do what you want, as written, is impossible. To change a user's primary group requires them to log out and log back in again. You will need to, as suggested above, use setGID to allow users to act on the directory as the primary group.

          Comment

          Working...