Announcement

Collapse
No announcement yet.

how to set umask 007 for new files?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] how to set umask 007 for new files?

    I have two users. I want to set for user_2 umask 007 so that every new file will have 770 (rwx rwx ---) privileges and so that user_1 can write and save changes to those files. I added user_1 to groups of user_2.
    In Gnome 2 I just needed to add umask 007 to .profile in home folder. So it looked like this:
    Code:
    # if running bash
    if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
    	. "$HOME/.bashrc"
        fi
    fi
    
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    
    umask 007
    But I see that in KDE it doesn't work.
    A new text file created by user_2 has 644 (-rw-r--r--).

    #2
    If I manually execute
    Code:
    umask 007
    touch testfile
    then testfile has permissions 0660/-rw-rw---- which is the result you should expect. (I think that making files executable has to be explicitly set, it's not controlled solely by umask.)

    Is .profile definitely getting called? It won't be if you have a .bash_profile. What is the output of plain
    Code:
    umask
    I'd rather be locked out than locked in.

    Comment


      #3
      Originally posted by SecretCode View Post
      Is .profile definitely getting called?
      I guess is it not called at all.
      Originally posted by SecretCode View Post
      It won't be if you have a .bash_profile.
      I do have .bash_profile file.
      Code:
      # .bash_profile
      
      # Get the aliases and functions
      if [ -f ~/.bashrc ]; then
      	. ~/.bashrc
      fi
      
      # User specific environment and startup programs
      
      PATH=$PATH:$HOME/.local/bin:$HOME/bin
      
      export PATH
      I also have .bashrc
      Code:
      # .bashrc
      
      # Source global definitions
      if [ -f /etc/bashrc ]; then
      	. /etc/bashrc
      fi
      
      # User specific aliases and functions
      Originally posted by SecretCode View Post
      What is the output of plain
      Code:
      umask
      0022

      Comment


        #4
        Try putting umask 007 in the user's .bash_profile (or .bashrc)
        I'd rather be locked out than locked in.

        Comment


          #5
          umask is set system wide in /etc/profile and for individuals in ~/.profile


          CORRECTION: system umask is now in /etc/login.defs
          Last edited by oshunluvr; Jun 02, 2012, 02:56 PM.

          Please Read Me

          Comment


            #6
            Originally posted by oshunluvr View Post
            umask is set system wide in /etc/profile and for individuals in ~/.profile
            But if you have a ~/.bash_profile (like gnomek), ~/.profile isn't read at all if the user's login shell is bash (.bash_profile takes precedence over .profile)...like SecretCode mentioned.

            I don't think newer *buntu releases have ~/.bash_profile by default anymore, but older (and upgraded) or new installations with old /home preserved still might have one.

            Comment


              #7
              Just to make it more confusing: according to the man page, bash_profile is executed when you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

              But, if you’ve already logged into your machine and open a new terminal window inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

              Please Read Me

              Comment


                #8
                Here's what Canonical says on the topic:

                Session-wide environment variables

                Environment variable settings that should affect just a particular user (rather then the system as a whole) should be set into:
                • [*=left]~/.pam_environment - This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line.

                Note: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables.If you are using KDE, see the KDE User-base page on this topic.Not recommended:
                • [*=left]~/.profile - This is probably the best file for placing environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.

                  [*=left]~/.bash_profile or ~./bash_login - If one of these file exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.

                  [*=left]~/.bashrc - Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. The performance cost of this will be negligible; the overhead of forking and execing bash will massively dominate the small cost of setting a handful of variables.

                Please Read Me

                Comment


                  #9
                  Looks like the pam umask module ('man pam_umask') can also pick up user specific umask from the user's GECOS field in /etc/passwd.

                  Just tried it, and seems to work without any other modifications (at least on quantal). Just another option, I guess.

                  EDIT: a command to add users umask to /etc/passwd:
                  Code:
                   sudo chfn -o "umask=007" username
                  (replacing "username" with the actual username whose umask to set...of course one can also edit /etc/passwd manually)

                  After a relog, user's umask is changed...note that I'm on quantal, can't be sure it'll work on older releases
                  Last edited by kubicle; Jun 02, 2012, 07:16 PM.

                  Comment


                    #10
                    Adding umask 007 to .bash_profile, .bashrc didn't work either. But
                    Code:
                     sudo chfn -o "umask=007" username
                    works. Thank all of you.

                    Comment

                    Working...
                    X