Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
elearning:workbooks:redhat:rh124en:l107 [2024/11/11 14:40] – created admin | elearning:workbooks:redhat:rh124en:l107 [2024/11/27 10:10] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 22: | Ligne 22: | ||
* The chown command | * The chown command | ||
* The chgrp command | * The chgrp command | ||
- | * LAB #2 - Extended | + | * LAB #2 - Advanced |
* 2.1 - SUID/SGID bit | * 2.1 - SUID/SGID bit | ||
* 2.2 - Inheritance Flag | * 2.2 - Inheritance Flag | ||
* 2.3 - Sticky bit | * 2.3 - Sticky bit | ||
+ | * LAB #3 - Extending Linux Permissions using ACLs and Attributes | ||
+ | * 3.1 - ACLs | ||
+ | * 3.2 - Attributes | ||
=====Presentation===== | =====Presentation===== | ||
Ligne 32: | Ligne 34: | ||
In its basic design, Linux uses a **DAC** security approach: | In its basic design, Linux uses a **DAC** security approach: | ||
- | ^ Security Type ^ Name ^ Description ^ | + | ^ Security Type ^ Name ^ Description ^ |
- | | DAC | // | + | | DAC | // |
=====Preparation===== | =====Preparation===== | ||
Ligne 53: | Ligne 55: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important**: | + | **Important** : The file **tux.jpg** is a text file. Linux does not use file extensions to determine file types. |
</ | </ | ||
Ligne 60: | Ligne 62: | ||
File permissions in Linux are communicated as follows: | File permissions in Linux are communicated as follows: | ||
- | {{free: | + | ^ User/ |
+ | | rwx | rwx | rwx | | ||
where r = read, w = write and x = executable | where r = read, w = write and x = executable | ||
- | Each inode stores the number | + | Each inode stores the UID of the user to whom the file belongs and the GID. When the file is opened, the system compares the user UID with the UID stored in the inode (Reference User). If these two numbers are identical, the user obtains the permissions of the file owner. If the numbers differ, the system checks whether the user is in the group referenced in the inode. If so, the user will have the permissions specified for the group. If no conditions are met, the user is given the permissions of ‘others’. |
The permissions for directories are slightly different: | The permissions for directories are slightly different: | ||
Ligne 102: | Ligne 105: | ||
^ t | sticky bit | | ^ t | sticky bit | | ||
- | for example the following command will give others write access to the file tux.jpg : | + | For example the following command will give others write access to the file tux.jpg : |
< | < | ||
Ligne 119: | Ligne 122: | ||
-r--r--rw-. 1 trainee trainee 0 Sep 27 12:42 tux.jpg | -r--r--rw-. 1 trainee trainee 0 Sep 27 12:42 tux.jpg | ||
</ | </ | ||
- | |||
- | <WRAP center round important 60%> | ||
- | **Important** : Only the file owner or root can change permissions. | ||
- | </ | ||
==Octal mode== | ==Octal mode== | ||
- | The chmod command can also be used with an octal representation | + | The chmod command can also be used with an octal representation. The octal values for access permissions are: |
- | {{free: | + | ^ User/ |
+ | | r | w | x | r | w | x | r | w | x | | ||
+ | | 400 | 200 | 100 | 40 | 20 | 10 | 4 | 2 | 1 | | ||
- | < | + | < |
- | **Important**: | + | **Important** : Full permissions |
</ | </ | ||
- | The chmod command | + | The chmod command takes the following form: |
- | chmod [ -R ] mode_octal | + | chmod [ -R ] Octal_value |
- | The following command | + | For example, the following command corresponds to the following |
< | < | ||
Ligne 147: | Ligne 148: | ||
</ | </ | ||
- | The default | + | The default permissions |
^ Directories | rwx rwx rwx | 777 | | ^ Directories | rwx rwx rwx | 777 | | ||
Ligne 197: | Ligne 198: | ||
</ | </ | ||
- | For example | + | For example: |
$ umask 002 [Enter] | $ umask 002 [Enter] | ||
- | before creating his file. | + | The value of the umask is deducted |
- | + | ||
- | umask is used to remove permissions | + | |
^ Maximum mask when creating a file | rw- rw- rw- | 666 | | ^ Maximum mask when creating a file | rw- rw- rw- | 666 | | ||
Ligne 209: | Ligne 208: | ||
^ Result | rw- rw- r-- | 664 | | ^ Result | rw- rw- r-- | 664 | | ||
- | + | Consider | |
- | In the following example, we use the touch command to create an empty file with the new default permissions: | + | |
< | < | ||
Ligne 252: | Ligne 250: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** - The owner of a file can only be changed | + | **Important** - Changing the owner of an object |
</ | </ | ||
Ligne 390: | Ligne 388: | ||
</ | </ | ||
- | =====LAB #2 - Extended | + | =====LAB #2 - Advanced |
====2.1 - SUID/SGID bit==== | ====2.1 - SUID/SGID bit==== | ||
- | Despite what you have just seen, in the first of the two windows below, you will notice that the **passwd** file located in the **/etc** directory has **rw- r-- r--** permissions and that it belongs | + | The following command prints to standard output information concerning |
< | < | ||
Ligne 402: | Ligne 400: | ||
</ | </ | ||
- | To remedy this apparent contradiction, | + | To remedy this apparent contradiction, |
* Set %%UserID%% bit ( SUID bit ) | * Set %%UserID%% bit ( SUID bit ) | ||
* Set %%GroupID%% bit ( SGID bit ) | * Set %%GroupID%% bit ( SGID bit ) | ||
- | When the SUID bit is set on a program, the user who launches the program | + | When a SUID bit is placed |
- | In the case of a password change, each user who launches the / | + | In the case of a password change, each user who launches the / |
The same function exists for the group, using the SGID bit. | The same function exists for the group, using the SGID bit. | ||
- | To assign permissions, use the chmod command: | + | To assign |
* chmod u+s file_name | * chmod u+s file_name | ||
* chmod g+s filename | * chmod g+s filename | ||
- | In base eight the values are as follows: | + | Or the Octal Mode where each advanced permission is assigned a value: |
* SUID = 4000 | * SUID = 4000 | ||
Ligne 467: | Ligne 465: | ||
====2.2 - Inheritance Flag==== | ====2.2 - Inheritance Flag==== | ||
- | The SGID bit can also be assigned to a directory. In this way, files and directories created inside will have the group of the parent directory as their group. This right is therefore called | + | The SGID bit can also be assigned to a directory. In this way, files and directories created inside will have the group of the parent directory as their group. This advanced file permission |
For example: | For example: | ||
Ligne 482: | Ligne 480: | ||
[root@redhat9 tmp]# touch inherit/ | [root@redhat9 tmp]# touch inherit/ | ||
- | [root@redhat9 tmp]# mkdir inherit/testrep | + | [root@redhat9 tmp]# mkdir inherit/testdir |
[root@redhat9 tmp]# cd inherit; ls -l | [root@redhat9 tmp]# cd inherit; ls -l | ||
total 0 | total 0 | ||
- | drwxr-sr-x. 2 root trainee 6 Sep 27 12:55 testrep | + | drwxr-sr-x. 2 root trainee 6 Sep 27 12:55 testdir |
-rw-r--r--. 1 root trainee 0 Sep 27 12:54 test.txt | -rw-r--r--. 1 root trainee 0 Sep 27 12:54 test.txt | ||
Ligne 493: | Ligne 491: | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important**: | + | **Important**: |
</ | </ | ||
Ligne 509: | Ligne 507: | ||
< | < | ||
- | [root@redhat9 inherit]# mkdir /tmp/repertoire_public; cd /tmp; chmod o+t repertoire_public | + | [root@redhat9 inherit]# mkdir /tmp/public_directory; cd /tmp; chmod o+t public_directory |
- | [root@redhat9 tmp]# ls -l | grep repertoire_public | + | [root@redhat9 tmp]# ls -l | grep public_directory |
- | drwxr-xr-t. 2 root root 6 Sep 27 12:56 repertoire_public | + | drwxr-xr-t. 2 root root 6 Sep 27 12:56 public_directory |
+ | </ | ||
+ | |||
+ | =====LAB #3 - Extending Linux Permissions using ACLs and File Attributes===== | ||
+ | |||
+ | ====3.1 - ACLs==== | ||
+ | |||
+ | An extension to the permissions under Linux are the ACLs. | ||
+ | |||
+ | To list the ACL's on a file, use the **getfacl** file: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# getfacl / | ||
+ | getfacl: Removing leading '/' | ||
+ | # file: home/ | ||
+ | # owner: root | ||
+ | # group: root | ||
+ | user::rw- | ||
+ | group:: | ||
+ | other:: | ||
+ | </ | ||
+ | |||
+ | To set ACLs on a file, you need to use the **setfacl** command: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# setfacl --set u:: | ||
+ | [root@redhat9 tmp]# getfacl / | ||
+ | getfacl: Removing leading '/' | ||
+ | # file: home/ | ||
+ | # owner: root | ||
+ | # group: root | ||
+ | user::rwx | ||
+ | user: | ||
+ | group:: | ||
+ | mask::rwx | ||
+ | other:: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** - A mask ACL entry specifies the maximum access which can be granted by any ACL entry except the user entry for the file owner and the other entry (entry tag type | ||
+ | ACL_MASK). | ||
+ | </ | ||
+ | |||
+ | Create the directory / | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# mkdir / | ||
+ | </ | ||
+ | |||
+ | ACLs on directories are managed slightly differently. Placing ACLs on the directory dir1 takes the following form : | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# setfacl --set d: | ||
+ | </ | ||
+ | |||
+ | The use of the letter **d** here means you are setting **default** ACLs. | ||
+ | |||
+ | Now create a file called **file1** in the **dir1** directory: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# touch / | ||
+ | </ | ||
+ | |||
+ | Once again use the getfacl command to see the ACLs: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# getfacl / | ||
+ | getfacl: Removing leading '/' | ||
+ | # file: home/ | ||
+ | # owner: root | ||
+ | # group: root | ||
+ | user::rwx | ||
+ | group:: | ||
+ | other:: | ||
+ | default: | ||
+ | default: | ||
+ | default: | ||
+ | |||
+ | [root@redhat9 tmp]# getfacl / | ||
+ | getfacl: Removing leading '/' | ||
+ | # file: home/ | ||
+ | # owner: root | ||
+ | # group: root | ||
+ | user::r-- | ||
+ | group:: | ||
+ | other:: | ||
+ | </ | ||
+ | |||
+ | The ACLs positioned on the file **file1** are the ACLs positioned by default on the parent directory. | ||
+ | |||
+ | Lastly the standard archiving commands under Linux do not understand ACLs. As a result, the ACLs need to be backed-up to a file using the following command: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 tmp]# cd / | ||
+ | [root@redhat9 dir1]# getfacl -R --skip-base . > backup.acl | ||
+ | [root@redhat9 dir1]# cat backup.acl | ||
+ | # file: . | ||
+ | # owner: root | ||
+ | # group: root | ||
+ | user::rwx | ||
+ | group:: | ||
+ | other:: | ||
+ | default: | ||
+ | default: | ||
+ | default: | ||
+ | </ | ||
+ | |||
+ | Restoring ACLs is acheived by using the following command: | ||
+ | |||
+ | # setfacl --restore=backup.acl [Enter] | ||
+ | |||
+ | ====Commande Line Switches==== | ||
+ | |||
+ | The command line switches for the getfacl command are : | ||
+ | |||
+ | < | ||
+ | [root@redhat9 dir1]# getfacl --help | ||
+ | getfacl 2.2.53 -- get file access control lists | ||
+ | Usage: getfacl [-aceEsRLPtpndvh] file ... | ||
+ | -a, --access | ||
+ | -d, --default | ||
+ | -c, --omit-header | ||
+ | -e, --all-effective | ||
+ | -E, --no-effective | ||
+ | -s, --skip-base | ||
+ | -R, --recursive | ||
+ | -L, --logical | ||
+ | -P, --physical | ||
+ | -t, --tabular | ||
+ | -n, --numeric | ||
+ | -p, --absolute-names | ||
+ | -v, --version | ||
+ | -h, --help | ||
+ | </ | ||
+ | |||
+ | The command line switches for the setfacl command are : | ||
+ | |||
+ | < | ||
+ | [root@redhat9 dir1]# setfacl --help | ||
+ | setfacl 2.2.53 -- set file access control lists | ||
+ | Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... | ||
+ | -m, --modify=acl | ||
+ | -M, --modify-file=file | ||
+ | -x, --remove=acl | ||
+ | -X, --remove-file=file | ||
+ | -b, --remove-all | ||
+ | -k, --remove-default | ||
+ | --set=acl | ||
+ | --set-file=file | ||
+ | --mask | ||
+ | -n, --no-mask | ||
+ | -d, --default | ||
+ | -R, --recursive | ||
+ | -L, --logical | ||
+ | -P, --physical | ||
+ | --restore=file | ||
+ | --test | ||
+ | -v, --version | ||
+ | -h, --help | ||
+ | </ | ||
+ | |||
+ | ====3.2 - Attributes==== | ||
+ | |||
+ | File attributes are an addition to the classic file permissions in Ext2/ | ||
+ | |||
+ | The principal attributes are : | ||
+ | |||
+ | ^ Attribute ^ Description ^ | ||
+ | | a | The file cannot be deleted and only the addition of data to the file is permitted. This attribute is often used for log files. | | ||
+ | | i | The file can neither be deleted, modified or moved. In addition, a link cannot be placed on the file. | | ||
+ | | s | The file will be physically destroyed when deleted. | | ||
+ | | D | Synchronous directory. | | ||
+ | | S | Synchronous file. | | ||
+ | | A | The date and time of the last file access are not updated in the inode. | | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** - Synchronous implies that the modifications are immediately written to disk. | ||
+ | </ | ||
+ | |||
+ | The two commands associated with attributes are: | ||
+ | |||
+ | ^ Command ^ Description ^ | ||
+ | | chattr | Modify the attributes. | | ||
+ | | lsattr | View attributes. | | ||
+ | |||
+ | To clarify the use of the two commands, create the directory **/ | ||
+ | |||
+ | < | ||
+ | [root@redhat9 dir1]# cd /root | ||
+ | [root@redhat9 ~]# mkdir -p attributs/ | ||
+ | </ | ||
+ | |||
+ | Create the files **file** et **dir/ | ||
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# touch attributs/ | ||
+ | [root@redhat9 ~]# touch attributs/ | ||
+ | </ | ||
+ | |||
+ | Now modify the attributes recursively: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# chattr +i -R attributs/ | ||
+ | </ | ||
+ | |||
+ | View the attributes using the **lsattr** command: | ||
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# lsattr -R attributs | ||
+ | ----i----------- attributs/ | ||
+ | |||
+ | attributs/ | ||
+ | ----i----------- attributs/ | ||
+ | |||
+ | ----i----------- attributs/ | ||
+ | </ | ||
+ | |||
+ | If you now try and move **file** to **/ | ||
+ | |||
+ | < | ||
+ | [root@redhat9 ~]# cd attributs; mv / | ||
+ | mv: cannot move '/ | ||
</ | </ | ||