Files
mkdocs/docs/Linux/permissions.md
2019-08-11 11:21:30 +02:00

172 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Permissions
#### Quelques commandes:
- su - temporarily become the superuser
- sudo - temporarily become the superuser
- chmod - modifier les droits d'accèès au fichier
- chown - changer le possesseur du fichier
- chgrp - changer a file's group ownership
- umask - permissions par défaut
```
-rwxrwxrwx
[- (fichier) ou d (dossier)] [rwx (possesseur) - rwx (groupe) - rwx (autres)]
```
| read value + | write value + | execute value = | numericvalue: | symbolic equivalent: |
| :----------: | :-----------: | :-------------: | :-----------: | :------------------: |
| | | | | |
| | | **1** | **1** | **x** |
| | **2** | | **2** | **w** |
| | **2** | **1** | **3** | **wx** |
| **4** | | | **4** | **r** |
| **4** | | **1** | **5** | **rx** |
| **4** | **2** | | **6** | **rw** |
| **4** | **2** | **1** | **7** | **rwx** |
#### chmod: change les permissions pour un fichier ou un dossier
```
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx —–- -–— = 111 000 000
```
et
```
rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r- = 100 in binary = 4
```
**Les réglages les plus courants:**
*-applications:*
```
777 (rwxrwxrwx)
755 (rwxr-xr-x)
700 (rwx——)
```
*-fichiers:*
```
666 (rw-rw-rw-)
644 (rw-rr)
600 (rw——-)
```
**Permissions pour les dossiers:**
- r: permet de lister le contenu d'un répertoire si l'attribut x est mis
- w: les fichiers à l'intérieur du répertoire peuvent être crées, effacés ou renommer si l'attribut x est mis
- x: permet d'entrer dans le répertoire (cd dir)
```
777 (rwxrwxrwx)
755 (rwxr-xr-x)
700 (rwx——)
```
```bash
bruno@macbook-pro:~$ ls -la
-rw-r--r--@ 1 bruno staff 848 6 aoû 09:20 backup-syno.tar.gz
bruno@macbook-pro:~/test-dossier-2$ chmod 777 backup-syno.tar.gz
bruno@macbook-pro:~$ ls -la
-rwxrwxrwx@ 1 bruno staff 848 6 aoû 09:20 backup-syno.tar.gz
```
#### chown: change le possesseur d'un fichier ou dossier (superuser)
```bash
bruno@macbook-pro:~$ ls -la
-rwxrwxrwx@ 1 bruno staff 848 6 aoû 09:20 backup-syno.tar.gz
bruno@macbook-pro:~$ sudo chown root backup-syno.tar.gz
Password:
bruno@macbook-pro:~$ ls -la
-rwxrwxrwx@ 1 root staff 848 6 aoû 09:20 backup-syno.tar.gz
```
#### chgrp: change le groupe d'un fichier ou dossier (superuser)
```bash
bruno@macbook-pro:~$ ls -la
-rwxrwxrwx@ 1 root staff 848 6 aoû 09:20 backup-syno.tar.gz
bruno@macbook-pro:~$ sudo chgrp admin backup-syno.tar.gz
bruno@macbook-pro:~$ ls -la
-rwxrwxrwx@ 1 root admin 848 6 aoû 09:20 backup-syno.tar.gz
```
#### umask:
définit les permissions par défaut d'un répertoire ou d'un fichier créé.
```bash
Par défaut:
$ umask
022
# 666 ANT NOT 022 = 644 (fichiers)
# 777 AND NOT 022 = 755 (dossiers)
$ umask -S
u=rwx,g=rx,o=rx
```
Modifier les permissions par défaut:
```bash
$ umask 777
# Personne n'aura accès aux fichiers nouvellement crées
```
#### setuid:
```
# chown root:root monshell.sh
# chmod 4755 monshell.sh
# exit
$ ./monshell.sh
```
#### Voir les autorisations au format octal:
**-Linux:**
```bash
stat -c '%n %a' *
```
**-OSX**:
```bash
bruno@Parallels-VM ~ $ stat -c '%n %a' *
apt-off.sh 755
Bureau 755
Documents 755
Images 755
```