User Tools

Site Tools


unix:file_permissions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
unix:file_permissions [2023/08/17 09:46]
manu
unix:file_permissions [2023/08/17 11:00] (current)
manu [Umask: file creation rights]
Line 17: Line 17:
  
 {{unix:​unix_file_permissions02.png?​650|}} {{unix:​unix_file_permissions02.png?​650|}}
 +
 +The first character indicates the type of file:
 +    – : represents an ordinary file
 +    d: represents a directory
 +    l: symbolic link
 +    c: represents a character device file
 +    b: represents a block device file
 +
  
 The table below gives numbers for all permission types of a File/​Directory. The table below gives numbers for all permission types of a File/​Directory.
Line 45: Line 53:
 $ ls -l testfile $ ls -l testfile
 -rw-r-xrwx ​ 1 user01 ​ users 1024  Nov 2 00:10  testfile -rw-r-xrwx ​ 1 user01 ​ users 1024  Nov 2 00:10  testfile
 +</​cli>​
 +
 +List file properties and octal permissions
 +<cli prompt='​$'>​
 +$ stat testfile
 +  File: testfile
 +  Size: 256             ​Blocks:​ 0          IO Block: 4096   ​directory
 +Device: 8000002200000007h/​9223372182883663879d ​ Inode: 774148 ​     Links: 2
 +Access: (0647/​-rw-r-xrwx) ​ Uid: ( 1000/  user01) ​  Gid: ( 1001/     ​mygroup01)
 +Access: 2023-08-17 09:​59:​39.000000000 +0200
 +Modify: 2022-04-11 11:​06:​46.000000000 +0200
 +Change: 2022-04-11 11:​06:​46.000000000 +0200
 + ​Birth:​ -
 </​cli>​ </​cli>​
  
Line 124: Line 145:
 ===== Advanced permission: ACL (access control list) ===== ===== Advanced permission: ACL (access control list) =====
  
 +Access Control List are not available on every kind of filesystems !
 ===== Ownership and groups ===== ===== Ownership and groups =====
  
Line 142: Line 163:
 -rw-r-xrwx ​ 1 user02 ​ mygroup01 1024  Nov 2 00:10  testfile -rw-r-xrwx ​ 1 user02 ​ mygroup01 1024  Nov 2 00:10  testfile
 </​cli>​ </​cli>​
 +
 +List owner and group of files and folders
 +<cli prompt='#'>​
 +[root@aix01]/​export#​ ls -lsa
 +   0 drwxr-xr-x ​   2 root     ​staff ​          256 Sep 25 2015  powerlinux
 +   4 drwxrwxrwx ​  16 root     ​nobody ​        4096 Feb 22 2022  rear
 +</​cli>​
 +
 +List userID and groupID of files and folders
 +<cli prompt='#'>​
 +[root@aix01]/​export#​ ls -n
 +drwxr-xr-x ​   2 0        1                 256 Sep 25 2015  powerlinux
 +drwxrwxrwx ​  16 0        4294967294 ​      4096 Feb 22 2022  rear
 +</​cli>​
 +
 +FIXME Do not forget, UNIX/Linux use IDs, name of user is just a mapping from UserID (based on /​etc/​passwd)
 +
 +==== Umask: file creation rights ====
 +
 +When you create a file with a specific user, a umask will defined the base rights on the created file.
 +<cli prompt='#'>​
 +[lpar2rrd@aix01]/​home/​lpar2rrd#​ umask
 +022
 +[lpar2rrd@aix01]/​home/​lpar2rrd#​ touch testfile
 +[lpar2rrd@aix01]/​home/​lpar2rrd#​ ls -lsa
 +   0 -rw-r--r-- ​   1 lpar2rrd staff             0 Aug 17 10:16 testfile
 +</​cli>​
 +
 +The flag consists of three octal digits, each representing the permissions masks for the user, the group, and others. The default permissions are determined by subtracting the umask value from ‘777’ for directories and ‘666’ for files. The default value of the umask is ‘022’.
 +
 +My file is created with permissions **666-022=644**
 +
 +On **AIX** a umask is specified by default into **/​etc/​security/​user**,​ you can specify one per user
 +  # chuser umask=022 user01
 +  ​
 +On **linux** the default mask is defined into **/​etc/​bashrc**,​ maybe also into **/​etc/​login.defs**. For custom, you can either add into homedir from every user, or globaly by script, you can add it to /etc/bashrc
 +<​code>​
 +if [ $UID -gt 199 ] && [ $(/​usr/​bin/​id -gn) == $(/​usr/​bin/​id -un) ]
 +then
 +  umask 444
 +else
 +  umask 555
 +fi
 +</​code>​
 +
unix/file_permissions.1692258372.txt.gz · Last modified: 2023/08/17 09:46 by manu