umask设置新文档的默认属性,有字符表达形式(Symbolic values)和八进制表达形式(Octal values)两种。
1 为所有用户统一修改默认的umask
You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:
# vi /etc/profile
OR
$ vi ~/.bashrc
Append/modify following line to setup a new umask:
umask 022
Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).
2 常用的umask
1)A umask of 022 allows only you to write data, but anyone can read data.
2)A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077.
3)A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it.
4)Set your umask to 007 to completely exclude users who are not group members.
3 数字的详细含义
Octal value : Permission
0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions
To set the umask 077 type the following command at shell prompt:
$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file
Sample outputs:
drwx------ 2 vivek vivek 4096 2011-03-04 02:05 dir1
-rw------- 1 vivek vivek 0 2011-03-04 02:05 file
理解上:
**(1)讲umask看做【Owner,Group,Others】三个对象的原始默认属性中需要去掉哪些权限(r=4, w=2, x=1, -=0)。例如,umask=003则表示Owner不用去掉任何权限,Group不需要去掉任何权限,Others需要去掉2+1即为w和x权限。
(2)档案的原始默认属性是666(-rw-rw-rw-),目录的原始默认属性为777(drwxrwxrwx)。**
4 用字符表达形式设置umask
r : read
w : write
x : execute
u : User ownership (user who owns the file)
g : group ownership (the permissions granted to other users who are
members of the file’s group)
o : other ownership (the permissions granted to users that are in
neither of the two preceding categories)
The following command will set umask to 077 i.e. a umask set to u=rwx,g=,o= will result in new files having the modes -rw——-, and new directories having the modes drwx——:
$ umask u=rwx,g=,o=
$ mkdir dir2
$ touch file2
$ ls -ld dir2 file2