Changing umask settings after cd

I have something strange to report. On my newly configured RHEL5 server, my shell is installed in / bin / bash. I have umask installed on 002 in .bashrc.

When I first log in, umask works correctly:

$ touch a $ ls -la -rw-rw-r-- etc..... 

if I create another file that it works:

 $ touch b $ ls -lb -rw-rw-r-- etc..... 

but ... if I change the directory (to any directory), then umask will be installed back 022:

 $ cd /var/www/whatever $ touch c $ ls -lc -rw-r--r-- etc..... 

totally freaky.

Has anyone seen anything like this? Can they come up with something?

why does umask setting change after cd'ing?

Thanks,

-Charlie

+4
source share
2 answers

Thanks to Barry Brown for the comment above - I tore my hair off with this problem (on OSX, not Linux), and this is really the rvm that was the culprit in my case. Check your .profile, .bash_profile etc. For a line like this:

 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

Comment on this, restart your shell, and this should fix the problem. I had no idea that rvm was so rude and intrusive. It is better to download it only when necessary, and not for each shell.

+4
source

Short answer: umask has four digits and it does not change arbitrarily, but / etc / profile and fiends set it to 022 by default.

Update
I somehow got carried away with this and forgot to answer your question correctly:

Make sure that the partition (if any) installed in the folder you are entering does not have the umask set. (just type mount )

Long answer:

man chmod Β§ 6: Numeric mode - from one to four octal digits (0-7), obtained by adding bits with values ​​4, 2 and 1. The assumed digits are considered leading zeros. The first digit selects the set user identifier (4) and sets the group identifier (2) and the restricted deletion or sticky (1) attributes. The second digit selects the permissions for the user who owns the file: read (4), write (2) and execute (1); the third chooses permissions for other users in the file group, with the same values; and the fourth for other users not in the file group, with the same values.

GNU coreutils 8.14 October 2011


I remember reading this manual page a few years ago, and never quite realizing what all of this means before I set up the table. Since I lost my lookup table, I will restore it here. Since I do not like the symbolic one but because it is more cumbersome to type (for example, chmod u + x), I will not be any mention of this.


Interpretation of chmod and umask

Possible settings: 4: read 2: write 1: execute

Possible values ​​of each digit with examples

  domain setuid user group world
 digit 1 2 3 4
 values ​​0-7 0-7 0-7 0-7

The "possible installation" values ​​in curly braces {} can be added together to create a valid permission bit (number).

Common examples

0755: the user can enter the folder and write (delete) files in this folder. If this mask is set in the file, the user can execute the file (i.e. /filenme.bin). The last two digits mean that the group, the file belongs, and the world (anyone else on the system) can execute the file as well. Applied to directories, this means that the group and the world can enter this directory.

0644: The user can read and write the file, but not execute it. The group and the world can only read the file. For a folder, this mask prevents anyone from this directory.

0600: Only the owner can read and write a file with this mask

0700: Only the owner of a folder can enter, read, and write the contents of a folder with this mask.

0000: useful for β€œhiding” files or for signaling (for yourself) that a file or folder should not be used.

Masks of meaningless

0200: If the user can write the file, he can also change the umask of the file.

Dangerous masks

0666: anyone can read, write and delete a file using this mask

0777: The same goes for the folder. If the binary is installed 777, then anyone can whatever they want in this file, and run it, even if it is on the system, a wide directory of binary files, such as / usr / bin.

4755: binaries owned by the superuser (root) will work with superuser permissions. The implications of this should be clear. Perhaps the intuitive setup of the interpreted script with 4755 will not have any effect since the script (e.g. bash script) is still running / bin / bash. The text file in which the script is stored is not executable.

In all of the above examples, the leading zero may be omitted for convenience.

Convert umask to chmod

To set the correct umask, all you have to do is subtract unwanted permissions from the "maximum mask", which is 0777 for folders and 666 for files.

To force the shell to create files with a default resolution of 644, set umask to 0022. For folders, the typical (desired) umask can be 755 and obtained by setting umask to 0022.

  0666 0777
 -0022 -0022
  ____ ____
  0644 0755

Relative links: https://unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts

+1
source

All Articles