The default file permissions UMASK

 

When the file or the file into the newly created folder Linux system there will always be a default permissions, then the privilege is how to set it?
umask is to set default permissions for files and directories

1. View the umask

  • Direct View,
[root@centos6 ~]# umask 
0022  
  • Modally display
[root@centos6 app]# umask -S
u=rwx,g=rx,o=rx
  • Output can be invoked, to redirect
[root@centos6 app]# umask -p
umask 0022

0022 represents the authority rwxr-xr-x, 0 is the first bit of special privileges, not considered here first.

2. File and directory permissions

  • File: The new file has execute permissions for all users is a terrible thing. So for file permissions for the default maximum is 666 rw-rw-rw
  • Contents: For a directory, x means that if permission to enter the directory. If a new directory x without permission can not enter this directory. That directory would be no meaning of existence. So the largest directory permissions are 777 drwxrwxrwx

3. The calculation of default permissions

  • File:
    ACCESS subtract umask code is equal to the default permissions, the result is odd, odd bits +1
  • The result is even
    666-022 = 644, converted to a permission rw- r- - r - -
  • = 135 If the mask
    666-025 = 641, 642 + 1 odd, is converted to the permissions rw- -r- - - w-

  • Contents:
    The maximum number equal rights subtract umask default permissions
  • 777-022 = 755 is converted into rights rwxr-xr-x

4. View Permissions

Create a file and directory permissions to view it.

[Root @ centos7data] #umask current umask of 0025
0025
[root@centos7data]#touch f1
[root@centos7data]#mkdir f2
[root@centos7data]#ll
total 0
-rw-r --- w- 1 root root 0 Nov 3 11:01 f1 new file is 666-025 = 641, plus an odd number, it was: 642, -rw-r - w-
drwxr-xw- 2 root root 6 Nov 3 11:01 f2 new directory is 777-025 = 752, drwx-rx-w-

5. umask setting method

  • Directly, take effect only temporarily, after the user logs off recovery
[root@centos6 app]# umask 0002
  • The specified user permanent
[root@centos6 app]# nano ~/.bashrc 
umask 0002
  • Permanent for all users
[root@centos6 app]# nano  /etc/.bashrc
umask 0002

6. Summary

  • The general root umask to 022
  • Ordinary users umask to 002
  • The larger the smaller the permissions umask

1. View the umask

  • Direct View,
[root@centos6 ~]# umask 
0022  
  • Modally display
[root@centos6 app]# umask -S
u=rwx,g=rx,o=rx
  • Output can be invoked, to redirect
[root@centos6 app]# umask -p
umask 0022

0022 represents the authority rwxr-xr-x, 0 is the first bit of special privileges, not considered here first.

2. File and directory permissions

  • File: The new file has execute permissions for all users is a terrible thing. So for file permissions for the default maximum is 666 rw-rw-rw
  • Contents: For a directory, x means that if permission to enter the directory. If a new directory x without permission can not enter this directory. That directory would be no meaning of existence. So the largest directory permissions are 777 drwxrwxrwx

3. The calculation of default permissions

  • File:
    ACCESS subtract umask code is equal to the default permissions, the result is odd, odd bits +1
  • The result is even
    666-022 = 644, converted to a permission rw- r- - r - -
  • 如果mask=135
    666-025=641,奇数+1为642,转换为权限rw- -r- - - w-

  • 目录:
    最大权限减去umask码等于默认权限
  • 777-022=755 转换为权限 rwxr-xr-x

4. 查看权限

创建文件与目录,查看其权限。

[root@centos7data]#umask    当前umask值为0025
0025
[root@centos7data]#touch f1
[root@centos7data]#mkdir f2
[root@centos7data]#ll
total 0
-rw-r---w- 1 root root 0 Nov  3 11:01 f1     新建的文件就是666-025=641,奇数加1,则为:642, -rw-r--w-
drwxr-x-w- 2 root root 6 Nov  3 11:01 f2     新建目录就是777-025=752, drwx-rx-w-

5. umask的设置方法

  • 直接设置,只是临时生效,用户注销后恢复
[root@centos6 app]# umask 0002
  • 对指定用户永久生效
[root@centos6 app]# nano ~/.bashrc 
umask 0002
  • 对所有用户永久生效
[root@centos6 app]# nano  /etc/.bashrc
umask 0002

6. 总结

  • 一般root的umask为022
  • 一般普通用户的umask为002
  • umask越小权限越大

Guess you like

Origin www.cnblogs.com/struggle-1216/p/11785454.html