07-05-2020

-La section Distributions regroupe Solus, Mint et Debian
-Section Windows
This commit is contained in:
2020-05-07 13:43:00 +02:00
parent 7e64b5c348
commit 6103008715
39 changed files with 1198 additions and 59 deletions

View File

@@ -0,0 +1,172 @@
# Linux Mint
#### Configuration matérielle:
```bash
System:
Host: MintBook
Kernel: 4.15.0-50-generic x86_64 bits: 64 compiler: gcc v: 7.3.0
Desktop: Cinnamon 4.0.10 wm: muffin dm: LightDM
Distro: Linux Mint 19.1 Tessa base: Ubuntu 18.04 bionic
```
```bash
Machine:
Type: Laptop System: Apple product: MacBookPro11,3
```
Quel hardware ?
```bash
# macOS
$ sysctl hw.model
hw.model: MacBookPro13,3
```
```bash
# ubuntu
$ sudo dmidecode -s system-product-name
MacBookPro11,3
```
https://wiki.ubuntu.com/MactelSupportTeam/CommunityHelpPages
https://help.ubuntu.com/community/MacBookPro
#### Firefox (et Thunderbird) en français:
-gestionnaire de paquets Synaptic. Chercher Firefox et installer le paquet de langue Fr
-dans `about:config` mettre `'fr'` à l'option `'general.useragent.locale'`
#### Chromium en français:
```bash
$ sudo apt-get install chromium-browser-l10n
```
#### SSH:
**Créer une clé SSH:**
```bash
$ ssh-keygen -t rsa -b 4096 -C "Clé sur MintBook"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bruno/.ssh/id_rsa):
Created directory '/home/bruno/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bruno/.ssh/id_rsa.
Your public key has been saved in /home/bruno/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:DvdgIfk9VTr4jQHW2/ehbu/1tX8iMkRAlcpfEwbud+M Clé sur MintBook
The key's randomart image is:
+---[RSA 4096]----+
| ...=+ . |
| ..o.o+o |
| o..oo.=+ |
| oo+.o+=...|
| . So+.+.=.o|
| = ooo + ..|
| ... . E o|
| o .o. *|
| o..o==|
+----[SHA256]-----+
```
#### Installer Typora:
```bash
wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
# or use
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE
# add Typora's repository
echo -e "\ndeb https://typora.io/linux ./" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
# install typora
sudo apt-get install typora
```
#### gksu est déprécié:
Depuis ubuntu 18.04, **gksu** est déprécié et n'est plus disponible.
Au lieu de la commande **gksu**:
```bash
$ gksu gedit /etc/nginx/sites-available/mint
```
il faut utiliser la commande **gedit admin://**:
```bash
$ gedit admin:///etc/nginx/sites-available/mint
```
#### Ouvrir gedit (en arrière-plan) depuis le terminal:
```bash
$ nohup gedit .dircolors >/dev/null &
```
```bash
$ gedit .dircolors &
```
#### Convertir une man-page en pdf:
```bash
man ls | gedit -
man ls | zenity --text-info
man -t ls | ps2pdf - ls.pdf
man -Tps ls | ps2pdf - > ls.pdf
# fonctions pur .zshrc:
fman () { until [[ -z $1 ]] ;do man -f "$1" 2>/dev/null && coproc man --html=firefox "$Extra close brace or missing open brace1"; shift; done; }
eman() { man -t "$1" | ps2pdf - "$1".pdf && setsid evince "$1".pdf; }
#Ouvrir. le .pdf:
xdg-open /path/to/file.pdf
evince /path/to/file.pdf
pdfopen, pdfclose - open or close a PDF file viewer
```
#### [cinnamon] Les Préférences ne se chargent pas:
cinnamon-settings doesn't open with pillow >= 6.0.0 (Python)
https://github.com/linuxmint/cinnamon/issues/8495#issuecomment-480221648
#### Impossible d'écrire sur le disque USB
```bash
$ id
uid=501(bruno) gid=20(staff) groups=20(staff),701(com.apple.sharepoint.group.1),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)
$ sudo chown bruno:users /mnt/MyDisk
```

View File

@@ -0,0 +1,47 @@
# Applications
Plusieurs solutions pour installer des applications dans Mint:
#### Gestionnaire de logiciels
#### Gestionnaire de paquets Synaptic
Liste de tous les paquets installés sur le système:
```bash
$ dpkg --get-selections > mylist.list
```
#### Flatpak
https://flathub.org/
install flatpak
install gnome-software-plugin-flatpak
#### Snap
install snapd
sudo snap install <package>
#### Appimage
-Télécharger l'application
-La rendre exécutable `$ chmod a+x app*.AppImage`
-La lancer `$ ./Subsurface*.AppImage
https://github.com/TheAssassin/AppImageLauncher

View File

@@ -0,0 +1,27 @@
# Backups
### Backup du dossier /home
#### Grsync
Créer une session "Sauvegarde home"
Réglages:
- choisir Source (/home/bruno) et Destination (/media/bruno/mon_disque_usb)
- <u>onglet "Options de base"</u>, cocher uniquement: Conserver la date, les permissions, le propriétaire, les groupes, effacer sur la destination, informations complémentaires, montrer la progression.
- <u>onglet "Options avancées"</u>, cocher uniquement: Préserver les périphériques, copier les liens symboliques comme liens symboliques, protéger les arguments distants.
- <u>onglet "Autres options"</u>: ne pas toucher
Cliquer sur Exécuter dans. le menu Fichier
<u>Sauvegardes suivantes:</u>
- ouvrir Grsync
- sélectionner la session « Sauvegarde home »
- cliquer sur « Exécuter ».

View File

@@ -0,0 +1,16 @@
# Grub
#### Configurer grub:
https://www.howtogeek.com/196655/how-to-configure-the-grub2-boot-loaders-settings/
```bash
$ sudo nano /etc/default/grub
```
[Démarrer Ubuntu en mode console](http://ubuntuhandbook.org/index.php/2014/01/boot-into-text-console-ubuntu-linux-14-04/)

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,251 @@
# Mises-à-jour
https://unix.stackexchange.com/questions/19470/list-available-updates-but-do-not-install-them
### Liste des m-à-j disponibles
**apt-get --just-print upgrade**
```bash
NOTE: Ceci n'est qu'une simulation !
apt-get a besoin des privilèges du superutilisateur
pour pouvoir vraiment fonctionner.
Veuillez aussi noter que le verrouillage est désactivé,
et la situation n'est donc pas forcément représentative
de la réalité !
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Calcul de la mise à jour... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
python-colorama python-decorator python-pathlib2 python-scandir
Veuillez utiliser « apt autoremove » pour les supprimer.
Les paquets suivants seront mis à jour :
python-pip-whl python3-pip
2 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour.
Inst python3-pip [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all]) []
Inst python-pip-whl [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python3-pip (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python-pip-whl (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
```
**aptitude search '~U' | wc -l**
```bash
aptitude search '~U'
i A python-pip-whl - Python package installer
i python3-pip - Python package installer
```
**apt list --upgradable**
```bash
apt list --upgradable
En train de lister... Fait
python-pip-whl/bionic-updates,bionic-updates 9.0.1-2.3~ubuntu1.18.04.1 all [pouvant être mis à jour depuis : 9.0.1-2.3~ubuntu1]
python3-pip/bionic-updates,bionic-updates 9.0.1-2.3~ubuntu1.18.04.1 all [pouvant être mis à jour depuis : 9.0.1-2.3~ubuntu1]
```
**apt-get -s dist-upgrade | awk '/^Inst/ { print $2 }'**
```bash
apt-get -s dist-upgrade | awk '/^Inst/ { print $2 }'
python3-pip
python-pip-whl
```
**sudo apt-get -V -u upgrade**
```bash
sudo apt-get -V -u upgrade
[sudo] password for bruno:
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Calcul de la mise à jour... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
python-colorama (0.3.7-1)
python-decorator (4.1.2-1)
python-pathlib2 (2.3.0-1)
python-scandir (1.7-1)
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
Les paquets suivants seront mis à jour :
python-pip-whl (9.0.1-2.3~ubuntu1 => 9.0.1-2.3~ubuntu1.18.04.1)
python3-pip (9.0.1-2.3~ubuntu1 => 9.0.1-2.3~ubuntu1.18.04.1)
2 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 1766 ko dans les archives.
Après cette opération, 2048 o d'espace disque supplémentaires seront utilisés.
Souhaitez-vous continuer ? [O/n]
```
**sudo apt-get -s -V -u upgrade**
```bash
sudo apt-get -s -V -u upgrade
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Calcul de la mise à jour... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
python-colorama (0.3.7-1)
python-decorator (4.1.2-1)
python-pathlib2 (2.3.0-1)
python-scandir (1.7-1)
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
Les paquets suivants seront mis à jour :
python-pip-whl (9.0.1-2.3~ubuntu1 => 9.0.1-2.3~ubuntu1.18.04.1)
python3-pip (9.0.1-2.3~ubuntu1 => 9.0.1-2.3~ubuntu1.18.04.1)
2 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour.
Inst python3-pip [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all]) []
Inst python-pip-whl [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python3-pip (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python-pip-whl (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
```
**apt-get update > /dev/null && apt-get --just-print upgrade | grep "Inst "**
```bash
sudo apt-get update > /dev/null && apt-get --just-print upgrade | grep "Inst "
Inst python3-pip [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all]) []
Inst python-pip-whl [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
```
**apt-get dist-upgrade </dev/null**
```bash
sudo apt-get dist-upgrade </dev/null
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances
Lecture des informations d'état... Fait
Calcul de la mise à jour... Fait
Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires :
python-colorama python-decorator python-pathlib2 python-scandir
Veuillez utiliser « sudo apt autoremove » pour les supprimer.
Les paquets suivants seront mis à jour :
python-pip-whl python3-pip
2 mis à jour, 0 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 1766 ko dans les archives.
Après cette opération, 2048 o d'espace disque supplémentaires seront utilisés.
Souhaitez-vous continuer ? [O/n] Annulation.
```
**apt list --upgradable**
```bash
apt list --upgradable
En train de lister... Fait
python-pip-whl/bionic-updates,bionic-updates 9.0.1-2.3~ubuntu1.18.04.1 all [pouvant être mis à jour depuis : 9.0.1-2.3~ubuntu1]
python3-pip/bionic-updates,bionic-updates 9.0.1-2.3~ubuntu1.18.04.1 all [pouvant être mis à jour depuis : 9.0.1-2.3~ubuntu1]
```
```bash
function a { read input;dpkg -l ${input} | grep " ${input} " | awk '{$1=$2=$3=$4="";print $0}' | sed 's/^ *//';unset input;};{ apt-get --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "$1 (\e[1;34m$2\e[0m -> \e[1;32m$3\e[0m)\n"}';} | while read -r line; do echo -en "$line $(echo $line | awk '{print $1}' | a )\n"; done;
python3-pip (9.0.1-2.3~ubuntu1 -> 9.0.1-2.3~ubuntu1.18.04.1) Python package installer
python-pip-whl (9.0.1-2.3~ubuntu1 -> 9.0.1-2.3~ubuntu1.18.04.1) Python package installer
```
apt-check is probably the most efficient scripting method.
**/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 1**
A very small modification shows you only the security updates.
**/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 2**
**apt-show-versions -u**
```bash
apt-show-versions -u
python-pip-whl:all/bionic-updates 9.0.1-2.3~ubuntu1 upgradeable to 9.0.1-2.3~ubuntu1.18.04.1
python3-pip:all/bionic-updates 9.0.1-2.3~ubuntu1 upgradeable to 9.0.1-2.3~ubuntu1.18.04.1
```
**sudo apt-get -qq update && apt-get -qq -s upgrade**
```bash
sudo apt-get -qq update && apt-get -qq -s upgrade
NOTE: Ceci n'est qu'une simulation !
apt-get a besoin des privilèges du superutilisateur
pour pouvoir vraiment fonctionner.
Veuillez aussi noter que le verrouillage est désactivé,
et la situation n'est donc pas forcément représentative
de la réalité !
Inst python3-pip [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all]) []
Inst python-pip-whl [9.0.1-2.3~ubuntu1] (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python3-pip (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
Conf python-pip-whl (9.0.1-2.3~ubuntu1.18.04.1 Ubuntu:18.04/bionic-updates [all])
```
### Infos sur un paquet
**apt-cache show <paquet>**
```bash
apt-cache show gcc-8-base
Package: gcc-8-base
Architecture: amd64
Version: 8.3.0-6ubuntu1~18.04.1
Multi-Arch: same
Priority: required
Section: libs
Source: gcc-8
Origin: Ubuntu
Maintainer: Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 113
Filename: pool/main/g/gcc-8/gcc-8-base_8.3.0-6ubuntu1~18.04.1_amd64.deb
Size: 18716
MD5sum: b231d33f61250fee66d1f4f41eebe9a0
SHA1: c56356523711c4b9f3f59cc4423254e4a293f46e
SHA256: 89415e0e9d940c81e33959f366f1bad1a94cfecacb538eb897be0e6038781a94
Homepage: http://gcc.gnu.org/
Description-en: GCC, the GNU Compiler Collection (base package)
This package contains files common to all languages and libraries
contained in the GNU Compiler Collection (GCC).
Description-md5: b6e93638a6d08ea7a18929d7cf078e5d
Task: minimal
Supported: 5y
Package: gcc-8-base
Architecture: amd64
Version: 8.3.0-6ubuntu1~18.04
Multi-Arch: same
Priority: required
Section: libs
Source: gcc-8
Origin: Ubuntu
Maintainer: Ubuntu Core developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 113
Filename: pool/main/g/gcc-8/gcc-8-base_8.3.0-6ubuntu1~18.04_amd64.deb
Size: 18648
MD5sum: ebd413aa6f179e38bb8e9f488b657fe6
SHA1: 95250c6482a359271804633e5a15ef3c8d38990f
SHA256: f94706768527e63e4a566d339897b3803b6cbb0a095f2bd267778110701e8508
Homepage: http://gcc.gnu.org/
Description-en: GCC, the GNU Compiler Collection (base package)
This package contains files common to all languages and libraries
contained in the GNU Compiler Collection (GCC).
Description-md5: b6e93638a6d08ea7a18929d7cf078e5d
Task: minimal
Supported: 5y
```

View File

@@ -0,0 +1,44 @@
# Recovery mode
https://wiki.ubuntu.com/RecoveryMode
#### Boot en mode recovery:
1. Appuyer sur **Shift** après le Bios pour accéder au **menu GNU Grub**
2. Sélectionner l'entrée avec **Recovery mode**
3. Dans le menu suivant, choisir **root**
4. Redémarrer avec la commande **reboot**
5. Ctrl+Alt+F3 pour démarrer Ubuntu dans la console
6. Taper login/password pour se logguer
7. Taper sudo reboot pour redémarrer
8. **Ctrl+Alt+F2** pour sortir de la console (ou F7)
9. **sudo systemctl start graphical.target** pour avoir l'écran classique de connexion
#### En cas de freeze:
Tout effacer dans :
```bash
/tmp
/home/.cache
```
Surveiller les logs:
```bash
dmesg
/var/log/syslog
```
Moniteur d'activité:
```bash
htop
```

View File

@@ -0,0 +1,150 @@
# Samba
D'origine Mint permet de se connecter à un partage SMB ou CIFS.
Mais pour créer partager sous Mint, il faut installer le paquet Samba.
**Dossier public partagé**
Créer un dossier public pour le partage:
```bash
$ sudo mkdir -p /home/the-user/sambashare
```
Régler le permissions pour que tout le monde puisse lire/écrire dedans:
```bash
$ sudo chown -R nobody:nogroup /home/hendadel/sambashare/
$ sudo chmod -R 0775 /home/hendadel/sambashare/
```
Editer le fichier de configuration de Samba:
```bash
$ sudo nano /etc/samba/smb.conf
```
Ajouter les lignes suivantes au fichier de configuration de Samba:
```bash
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = hendadel-VBox
security = user
[SambaShare]
Comment = Samba Shared Directory
path = /home/hendadel/sambashare
writable = yes
guest ok = yes
read only = no
force user = nobody
```
Tester le fichier de configuration de Samba:
```bash
$ testparm
```
Redémarrer Samba:
```bash
$ sudo service smbd restart
```
Accéder au répertoire:
```bash
\192.168.1.8\sambashare
-- accès sans l/p --
```
**Dossier privé partagé**
Créer un groupe, y ajouter des utilisateurs et membres. Uniquement les membres de ce groupe auront accès au dossier partagé.
Créer un groupe:
```bash
$ sudo addgroup smbgroup
```
Ajouter un utilisateur au groupe smbgroup:
```bash
$ sudo usermod -aG smbgroup the-user
```
Donner un mot-de-passe: Give a password for the samba user.
```bash
$ sudo smbpasswd -a the-user
```
Créer un répertoire pour partager en privé:
```bash
$ sudo mkdir -p /home/the-user/sambaprivate/
```
Régler les permissions du dossier pour que seuls root et les membres du groupe accèdent au dossier partagé:
```bash
$ sudo chown -R root:smbgroup /home/hendadel/sambaprivate/
$ sudo chmod -R 0770 /home/hendadel/sambaprivate/
```
Editer le fichier de configuration de Samba pour y ajouter le nouveau répertoire.
```bash
$ sudo vi /etc/samba/smb.conf
```
Ajouter ce qui suit:
```bash
[SambaPrivate]
path = /home/hendadel/sambaprivate
valid users = @smbgroup
guest ok = no
writable = yes
browsable = yes
```
Redémarrer le service Samba.
```bash
sudo service smbd restart
```
Tester le fichier de configuration de Samba:
```bash
$ testparm
```
Accéder au répertoire:
```bash
\192.168.1.8\sambashare
-- demande l/p --
```

View File

@@ -0,0 +1,38 @@
# systemctl
```bash
To list systemd services we will use systemctl command as below
# systemctl list-unit-files
To list active systemd services run
# systemctl | more
# systemctl list-units --type service
You can pipe the output to grep to search a more specific service as shown below
# systemctl | grep "apache2"
To check the services alongside the ports they are listening.
# netstat -pnltu
For example, to check if OpenSSH is running on your system, run
# systemctl status sshd
Alternatively, you can use the syntax below to check if the service is active
# systemctl is-active sshd
o check if OpenSSH is enabled, run
# systemctl is-enabled sshd
Ancien system:
check the status of OpenSSH, run
# service sshd status
You can also check all services by running
# chkconfig --list
```

View File

@@ -0,0 +1,61 @@
# Installer un serveur ftp (vsftpd)
#### Installer vsftpd:
```bash
$ sudo apt install vsftpd
```
#### Configurer vsftpd:
```bash
$ sudo mv -v /etc/vsftpd.conf /etc/vsftpd.conf.bk
$ sudo touch /etc/vsftpd.conf
$ sudo nano /etc/vsftpd.conf
```
```nginx
listen=YES
listen_ipv6=NO
connect_from_port_20=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=45000
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
## userlist_deny=NO
```
#### Liste des utilisateurs:
```bash
$ sudo nano /etc/vsftpd.userlist
```
#### Redémarrer vsftpd:
```bash
$ sudo systemctl restart vsftpd
$ sudo systemctl status vsftpd
```
https://linuxhint.com/setup_ftp_server_vsftpd_ubuntu/
https://doc.ubuntu-fr.org/vsftpd
https://vitux.com/install-vsftpd-ftp-server-tls-ubuntu/

View File

@@ -0,0 +1,670 @@
# Nginx / PHP / MySQL
## Installer un serveur web
#### Installer Nginx:
```bash
$ sudo apt-get install nginx
```
##### Version de Nginx:
```bash
$ nginx -v
nginx version: nginx/1.14.0 (Ubuntu)
```
##### Démarrer,activer et vérifier l'étât du service Nginx.
```bash
$ sudo systemctl start nginx.service
$ sudo systemctl enable nginx.service
$ sudo systemctl status nginx.service
```
```bash
# ps -ef | grep -i nginx
root 18596 13:16 nginx: master process ./nginx
nobody 18597 13:16 nginx: worker process
```
https://www.nginx.com/resources/wiki/start/
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
https://wiki.debian.org/Nginx/DirectoryStructure
##### Arborescence:
```bash
bruno@MintBook:/etc/nginx$ tree
.
├── conf.d
├── fastcgi.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── modules-available
├── modules-enabled
│   ├── 50-mod-http-geoip.conf -> /usr/share/nginx/modules-available/mod-http-geoip.conf
│   ├── 50-mod-http-image-filter.conf -> /usr/share/nginx/modules-available/mod-http-image-filter.conf
│   ├── 50-mod-http-xslt-filter.conf -> /usr/share/nginx/modules-available/mod-http-xslt-filter.conf
│   ├── 50-mod-mail.conf -> /usr/share/nginx/modules-available/mod-mail.conf
│   └── 50-mod-stream.conf -> /usr/share/nginx/modules-available/mod-stream.conf
├── nginx.conf
├── proxy_params
├── scgi_params
├── sites-available
│   └── default
├── sites-enabled
│   └── default -> /etc/nginx/sites-available/default
├── snippets
│   ├── fastcgi-php.conf
│   └── snakeoil.conf
├── uwsgi_params
└── win-utf
```
##### Configuration:
Le fichier `/etc/nginx/nginx.conf` contient la configuration générale de nginx.
```nginx
user www-data;
```
Créer un fichier qui contiendra les configurations du site dans le répertoire `/etc/nginx/sites-available/`.
Le dossier contient déjà un fichier par défaut: `/etc/nginx/sites-available/default`
```bash
$ cd /etc/nginx/sites-available/
$ sudo cp default mint
$ sudo gedit mint
```
Modifier les lignes:
- root: le dossier root du site
- index: ajouter index.php
- server_name
Dé-commenter les lignes:
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/run/php/php7.2-fpm.sock;
```nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /home/bruno/Sites;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name mintbook.local;
access_log /var/log/nginx/access_log;
error_log /var/log/nginx/error_log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
```
Donner les droits à Nginx pour le dossuier root:
```bash
$ sudo chown -R www-data:www-data /home/bruno/Sites
```
Déclarer le socket Unix de PHP-FPM au niveau de Nginx: il faut modifier ou créer le fichier `/etc/nginx/conf.d/php7-fpm.conf`
```nginx
upstream php7.2-fpm-sock {
server unix:/run/php/php7.2-fpm.sock;
}
```
Créer ensuite un lien symbolique de ce fichier dans le répertoire `/etc/nginx/sites-enabled/` afin dactiver le site.
Il est à noter que pour désactiver le site temporairement il suffit de supprimer le lien symbolique qui est dans `sites-enabled` et pour le réactiver, il faut refaire un lien symbolique avec le fichier qui se trouve dans `site-available`.
```bash
$ cd /etc/nginx/sites-enabled/
$ ln -s /etc/nginx/sites-available/mint mint
$ ls -la
total 8
drwxr-xr-x 2 root root 4096 mai 30 12:56 .
drwxr-xr-x 8 root root 4096 mai 30 10:40 ..
lrwxrwxrwx 1 root root 34 mai 30 10:40 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 31 mai 30 12:56 mint -> /etc/nginx/sites-available/mint
$ sudo rm default
```
##### Tester la configuration Nginx:
```bash
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```
##### Relancer Nginx:
```bash
$ sudo service nginx reload
```
##### Commandes Nginx:
Démarrer nginx: `$ sudo systemctl start nginx`
Arrêter nginx: `$ sudo systemctl stop nginx`
Redémarrer nginx: `$ sudo systemctl restart nginx`
Recharger nginx après une modification de configuration: `$ sudo systemctl reload nginx`
Désactiver le démarrage auto de nginx avec le système: `$ sudo systemctl disable nginx`
Activer le démarrage auto de nginx avec le système: `$ sudo systemctl enable nginx`
##### Vérifier l'étât de Nginx:
```bash
$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-05-30 10:40:04 CEST; 21h ago
Docs: man:nginx(8)
Main PID: 19485 (nginx)
Tasks: 9 (limit: 4915)
CGroup: /system.slice/nginx.service
├─19485 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─30594 nginx: worker process
├─30595 nginx: worker process
├─30596 nginx: worker process
├─30597 nginx: worker process
├─30598 nginx: worker process
├─30599 nginx: worker process
├─30600 nginx: worker process
└─30601 nginx: worker process
```
#### HTTPS:
https://linoxide.com/linux-how-to/create-self-signed-ssl-certificate-nginx-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-18-04
##### Créer une clé et un certificat. auto-signé:
```bash
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/mintbook.local.key -out /etc/ssl/certs/mintbook.local.crt
[sudo] password for bruno:
Generating a 2048 bit RSA private key
...........+++
.................+++
## writing new private key to '/etc/ssl/private/mintbook.local.key'
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
## If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:Bourgogne
Locality Name (eg, city) []:Dijon
Organization Name (eg, company) [Internet Widgits Pty Ltd]:clicclac.info
Organizational Unit Name (eg, section) []:Web
Common Name (e.g. server FQDN or YOUR name) []:mintbook.local
Email Address []:enzo@clicclac.info
```
##### Paramètres Diffie-Hellman (DH):
```
$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
..........................................+.....+..
```
##### Configuration SSL:
```bash
$ sudo nano /etc/nginx/snippets/self-signed.conf
```
```ini
ssl_certificate /etc/ssl/certs/mintbook.local.crt;
ssl_certificate_key /etc/ssl/private/mintbook.local.key;
```
```bash
$ sudo nano /etc/nginx/snippets/ssl-params.conf
```
```ini
ssl_protocols TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# Disable strict transport security for now. You can uncomment the following
# line if you understand the implications.
# add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
```
```bash
$ cd /etc/nginx/sites-available
$ sudo cp mint mint-ssl
$ sudo gedit mint-ssl
```
```ini
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
include snippets/self-signed.conf;
include snippets/ssl-param.conf;
```
#### Installer PHP:
```bash
$ sudo apt-get install php-fpm
```
```bash
$ which php
/usr/bin/php
$ php -v
PHP 7.2.17-0ubuntu0.18.04.1 (cli) (built: Apr 18 2019 14:12:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.17-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
```
##### Configurer PHP-FPM:
- PHP et Nginx sur la même machine => socket Unix
- PHP et Nginx sur la même machine => socket TCP
```bash
$ sudo gedit /etc/php/7.2/fpm/pool.d/www.conf
```
Vérifier que PHP-Fpm utilise le Socket Unix (NGINX et PHP sur la même machine):
```bash
;listen = 127.0.0.1:9000
listen = /run/php/php7.2-fpm.sock
```
##### Configurer PHP.ini:
```bash
$ nano /etc/php/7.2/fpm/php.ini
```
```ini
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 64M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = Europe/Paris
```
*cgi.fix_pathinfo : lactivation de ce paramètre permet à PHP de naccepter que les URI qui existent réellement sur le serveur.*
##### Configurer Nginx:
```bash
$ sudo gedit /etc/nginx/sites-availables
```
Activer php:
```nginx
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
```
Redémarrer le service php-fpm:
```bash
$ sudo service php7.2-fpm restart
```
##### Installer les modules PHP manquants:
Dans le Gestionnaire de paquets Synaptic, installer les modules GD, MySQL...
Manque: apcu, gmp, odbc, yaml
ou
```bash
$ sudo apt-cachesearch php- | less
$ sudo apt-get install "module name"
$ sudo apt-cache show "module name"
```
#### Installer MySQL (MariaDB):
```bash
$ sudo apt-get -y install mariadb-server mariadb-client
```
##### Démarrer, activer et vérifier l'étât du service MariaDB:
```bash
$ sudo systemctl start mysql.service
$ sudo systemctl enable mysql.service
$ sudo systemctl status mysql.service
```
##### Securiser l'installation de MariaDB:
```bash
$ sudo mysql_secure_installation
Enter current password for root (enter for none): Enter Your Current Password
OK, successfully used password, moving on...
Set root password? [Y/n] n
... skipping.
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
```
~~l/p: root/sncfp1p2~~
##### Désinstaller mysql:
```bash
$ sudo service mysql stop
$ sudo apt-get remove --purge mysql*
$ sudo apt-get autoremove
$ sudo apt-get autoclean
$ sudo rm -rf /var/lib/mysql
$ sudo rm -rf /etc/mysql
```
##### Se connecter à MySQL:
```bash
$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.1.38-MariaDB-0ubuntu0.18.04.2 Ubuntu 18.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
```
##### Depuis ubuntu 18.04
Se logguer dans mysql en root.
Créer un utilisateur et lui donner tous les droits:
```mysql
CREATE USER 'username'@'localhost' IDENTIFIED BY 'the_password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
```
Créer un utilisateur avec le même nom et lui donner tous les droits:
```mysql
CREATE USER 'username'@'%' IDENTIFIED BY 'the_password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
```
Le compte 'username'@localhost' est utilisé quand on se connecte depuis la machine locale.
Le compte 'username'@'%' est utilisé pour se connecter depuis n'importe quelle machine.
```mysql
SHOW GRANTS FOR username;
FLUSH PRIVILEGES;
```
#### Configurer le firewall ubuntu:
```bash
$ sudo ufw app list
[sudo] password for bruno:
Available applications:
CUPS
Nginx Full
Nginx HTTP
Nginx HTTPS
syncthing
syncthing-gui
```
<u>Liste les profils disponibles:</u>
Profile Nginx Full: ouvre les ports 80 (http) et 443 (https)
Profile Nginx HTTP: ouvre les ports 80 (http)
Profile Nginx HTTPS: ouvre les ports 443 (https)
##### Activer le profile Nginx Full:
```bash
$ sudo ufw allow 'Nginx Full'
Rule added
Rule added (v6)
```
##### Status du firewall:
```bash
$ sudo ufw status
Status: active
To Action From
------
Nginx Full ALLOW Anywhere
Nginx Full (v6) ALLOW Anywhere (v6)
```
####