<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Wed, 29 Apr 2026 01:00:17 +0200 -->
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Wiki Les geekeries de rungis]]></title>
		<atom:link href="https://geekrungis.fr/syndication/rss/wiki/5" rel="self" type="application/rss+xml"/>
		<link>https://geekrungis.fr</link>
		<description><![CDATA[Derniers articles de la catégorie Services]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>fr</language>
		<generator>PHPBoost</generator>
		
            <item>
                <title><![CDATA[Paramétrer simplement l'envoi de mail sur un serveur]]></title>
                <link>https://geekrungis.fr/wiki/parametrer-simplement-l-envoi-de-mail-sur-un-serveur</link>
                <guid>https://geekrungis.fr/wiki/parametrer-simplement-l-envoi-de-mail-sur-un-serveur</guid>
                <description><![CDATA[Dans cet article, nous allons décrire comment paramétrer l'envoi de mail à a partir d'un serveur. Cela peut s'avérer très utile pour qu'un serveur envoi des mails lors de la réalisation d'une tache, ou pour intégrer l''envoi d'un mail dans un script.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-installationdespaquetsncessaires">Installation des paquets nécessaires</h2><br />

<br />
Je donne les commandes ici pour Debian et dérivés mais ces paquets existent sur d'autres distributions.<br />
<br />
On installe les paquets msmtp, msmtp-mta ainsi que bsd-mailx.<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apt <span style="color: #c20cb9; font-weight: bold;">install</span> msmtp msmtp-mta bsd-mailx</pre></pre></div></div><br />
<br />
Ce dernier paquet est utile seulement si vous souhaitez utiliser la commande mail pour l'envoi des messages. Sans ce paquet, seule la commande msmtp fonctionne. Pour un script, ce n'est pas grave mais certains logiciels envoient des mails seulement par la commande mail. C'est le cas par exemple de unattended-upgrades<br />
<br />
Vérifier ensuite que le système utilise bien msmtp pour l'envoi de mails :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span>
&nbsp;</pre></pre></div></div><br />
<br />
Doit retourner :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span> -<span style="color: #000000; font-weight: bold;">></span> ..<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>msmtp
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-configuration">Configuration</h2><br />

<br />
Pour fonctionner, le service s'appui sur le fichier de configuration suivant, à éditer :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>msmtprc</pre></pre></div></div><br />
<br />
<span class="message-helper bgc notice"><br />
Ce fichier fonctionne pour envoyer des mail à partir du compte root. Pour envoyer un mail à partir d'un autre utilisateur, créer un fichier .msmtprc dans le dossier utilisateur<br />
</span><br />
<br />
On peut y insérer les options par défaut pour tous les comptes que l'on paramètre :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
# Valeurs par defaut pour tous les comptes.
defaults
auth           on
tls            on
tls_starttls   off
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        /var/log/msmtp.log
&nbsp;</pre></pre></div></div><br />
<br />
<span class="message-helper bgc warning"><br />
Attention à la configuration en fonction de votre fournisseur de mail. Par exemple, Infomaniak ne supporte pas le STARTTLS il faut utiliser le port 465, activer tls mais désactiver STARTTLS<br />
</span><br />
<br />
<br />
<span class="message-helper bgc warning"><br />
L'utilisateur qui enverra le mail doit avoir accès au fichier de log. On peut donc soit créer un fichier de log dans le dossier de l'utilisateur soit lui donner les droits sur ce fichier de log.<br />
</span><br />
<br />
On créé ensuite une partie pour chaque compte que l'on souhaite paramétrer :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
account            [nom du compte]
host               [serveur smtp]
port               [port smtp]
from               [adresse mail] ou [Nom expéditeur]
user               [utilisateur du compte mail utilisé]
password           [mot de passe du compte mail]
&nbsp;</pre></pre></div></div><br />
<br />
Par exemple, pour un compte gmail<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
account            Gmail rungis
host               smtp.gmail.com
port               587
from               Rungis
user               votreadressemail@gmail.com
password           MonMotDePasseGmail
&nbsp;</pre></pre></div></div><br />
<br />
Ajouter une ligne à la fin du fichier pour spécifier le nom du compte par défaut à utiliser<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
account default : Gmail rungis
&nbsp;</pre></pre></div></div><br />
<br />
<span class="message-helper bgc warning"><br />
Vu que le fichier contient le mot de passe du compte mail, pensez à réduire les droits sur ce fichier avec les commandes suivantes :<br />
</span><br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root:root <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>msmtprc
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>msmtprc
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-test">Test</h2><br />

<br />
Vous pouvez ensuite tester l'envoi d'un mail par la commande suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Corps du mail"</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">"Sujet du mail"</span> <span style="color: #660033;">--</span> destinataire<span style="color: #000000; font-weight: bold;">@</span>gmail.com</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-installation-de-mutt">Installation de mutt</h2><br />

<br />
msmtp fonctionne seul mais mutt offre plus de fonctionnalités, notamment l'envoi de pièces jointes.<br />
<br />
On installe mutt :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
apt update
apt <span style="color: #c20cb9; font-weight: bold;">install</span> mutt
&nbsp;</pre></pre></div></div><br />
<br />
Puis on créé le fichier .muttrc dans le dossier home de l'utilisateur :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">vim</span> ~<span style="color: #000000; font-weight: bold;">/</span>.muttrc
&nbsp;</pre></pre></div></div><br />
<br />
Et on y ajoute les lignes suivantes :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">sendmail</span>=<span style="color: #ff0000;">"/bin/msmtp"</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">use_from</span>=no
&nbsp;</pre></pre></div></div><br />
<br />
<span class="message-helper bgc notice"><br />
Pas besoin de plus d'options, le reste est déjà défini dans le fichier de configuration de msmtp<br />
</span><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-test-avec-mutt">Test avec mutt</h2><br />

<br />
On peut tout d'abord créer une petite pièce jointe de test<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"coucou"</span> <span style="color: #000000; font-weight: bold;">>></span> fichiertest.txt
&nbsp;</pre></pre></div></div><br />
<br />
Puis on envoi ce fichier à l'adresse souhaitée :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"texte dans le mail"</span> <span style="color: #000000; font-weight: bold;">|</span> mutt <span style="color: #660033;">-s</span> <span style="color: #ff0000;">"Sujet du mail"</span> <span style="color: #660033;">-a</span> fichiertest.txt <span style="color: #660033;">--</span> adresse<span style="color: #000000; font-weight: bold;">@</span>mail.from
&nbsp;</pre></pre></div></div><br />]]></description>
                <pubDate>Sun, 12 Nov 2023 19:27:32 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Créer un serveur de fichiers avec samba]]></title>
                <link>https://geekrungis.fr/wiki/creer-un-serveur-de-fichiers-avec-samba</link>
                <guid>https://geekrungis.fr/wiki/creer-un-serveur-de-fichiers-avec-samba</guid>
                <description><![CDATA[Un nouvel article un peu long pour tracer ma façon que j'ai utilisée pour créer un serveur de fichier à l'aide de samba.<br />
Pendant un long moment, j'ai utilisé openmediavault qui est une distribution basée sur debian et conçue pour faire son NAS DIY. Bien entendu, ce serveur est hébergé sur proxmox.<br />
<br />
Au bout d'un certain temps, j'en ai eu marre des ressources qu'il consommait, de devoir aller sur l'interface pour valider des mises à jour et parce que cela m'intéressait d'apprendre à paramétrer un serveur de fichier moi-même.<br />
<br />
Pour cela, j'ai utilisé une bonne vieille debian !<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-installation-des-paquets-necessaires">Installation des paquets nécessaires</h2><br />

<br />
Pour mes besoins, voici la liste des paquets que j'ai installés :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> samba (pour le serveur de fichier)
    </li><li class="formatter-li"> mergerfs (pour regrouper des disques durs ensemble et ne faire qu'un système de fichier visible)
    </li><li class="formatter-li">
    </li><li class="formatter-li">
    </li><li class="formatter-li">
</li></ul><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-parametrages-initiaux">Paramétrages initiaux</h2><br />

<br />
Quelques paramétrages initiaux à faire...<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-attribuer-une-ip-fixe">Attribuer une IP fixe</h3><br />

<br />
Pour cela, sur debian, on modifie le fichier /etc/network/interfaces et on remplace :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
iface enp3s0 inet dhcp
&nbsp;</pre></pre></div></div><br />
<br />
par<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
iface enp3s0 inet static
    address 192.168.1.15
    netmask 255.255.255.0
    gateway 192.168.1.254
&nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-modifier-le-serveur-dns">Modifier le serveur dns</h3><br />

<br />
Pour cela, on modifie le fichier /etc/resolv.conf et on ajoute les lignes voulues :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
search vds.lan
nameserver 192.168.1.21
nameserver 1.1.1.1
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-passthrough-des-disques-durs">Passthrough des disques durs</h2><br />

<br />
Passthrough signifie qu'un périphérique branché sur l'hôte d'un virtualiseur (dans mon cas, l'ordinateur sur lequel est installé proxmox) va être transmis tel quel à une VM. Cela signifie que le périphérique ne pourra pas être utilisé par proxmox ou par une autre VM.<br />
<br />
Dans mon cas, j'ai 3 disques durs que je vais transmettre directement à ma debian. C'est sur ces disques que se trouvent tous mes fichiers qui seront disponibles via samba.<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-recuperer-les-identifiants-des-disques">Récupérer les identifiants des disques</h3><br />

<br />
Tout d'abord on récupère les UUID de nos disques avec la commande suivante :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
lsblk <span style="color: #660033;">-o</span> +MODEL,SERIAL,WWN,UUID
&nbsp;</pre></pre></div></div><br />
<br />
Cette commande vous permet également de repérer les disques par leur numéro de série si besoin.<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-passthrough-sur-proxmox">Passthrough sur proxmox</h3><br />

<br />
Pour attacher le disque souhaité à la VM :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
qm <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">109</span> <span style="color: #660033;">-scsi2</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>disk<span style="color: #000000; font-weight: bold;">/</span>by-uuid<span style="color: #000000; font-weight: bold;">/</span>eae45129-e294-4d27-8f52-3a562764ed33
&nbsp;</pre></pre></div></div><br />
<br />
<span class="message-helper notice"><br />
109 est le numéro de la VM<br />
eae45129-e294-4d27-8f52-3a562764ed33 est l'UUID du disque souhaité<br />
</span><br />]]></description>
                <pubDate>Sat, 14 Oct 2023 16:59:57 +0200</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[L'utilitaire screen]]></title>
                <link>https://geekrungis.fr/wiki/l-utilitaire-screen</link>
                <guid>https://geekrungis.fr/wiki/l-utilitaire-screen</guid>
                <description><![CDATA[Petit mémo sur l'utilisation de l'outil screen sur linux, petit utilitaire que j'adore pour deux fonctionnalités principales que nous allons voir rapidement :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> Avoir un terminal qui tourne en fond sur lequel on peut revenir quand on veut et même à partir d'un autre client (très pratique en ssh)
    </li><li class="formatter-li"> Diviser son terminal en deux ou plusieurs parties<br />
</li></ul><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-les-commandes-de-base">Les commandes de base</h2><br />

<br />
Ici on va voir quelques commandes de base pour lancer screen. Ce qui est top avec screen, c'est que lorsque vous le lancez, vous pouvez ensuite à l'intérieur de ce screen lancer une commande ou un script et sortir de ce screen pendant que la commande ou le script s'exécute. C'est super pratique pour un script ou une commande qui va durer longtemps. Gros avantage (notamment en ssh), si vous perdez la connexion, pas de problème ! Vous vous reconnectez, vous réattachez le screen et vous vous retrouvez sur votre écran comme si de rien n'était.<br />
De même, vous pouvez vous connecter en ssh sur un serveur, lancer un screen, lancer une commande longue ou un script à l'intérieur puis vous détachez du screen et vous déconnecter du serveur. Vous pourrez vous reconnecter en ssh plus tard (même à partir d'un autre client) et rouvrir le screen pour voir où en est la commande ou le script.<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;"># Démarrer un screen (test est le nom qu'on donne au screen, on met ce qu'on veut)</span>
<span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-S</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #666666; font-style: italic;"># Sortir du screen en le supprimant</span>
<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #666666; font-style: italic;"># Se détacher du screen</span>
Ctrl+A puis D
<span style="color: #666666; font-style: italic;"># Se réattacher au screen</span>
<span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-r</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #666666; font-style: italic;"># Se réattacher au screen alors que celui-ci est déjà "Attached" (après une perte de connexion par exemple)</span>
<span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-R</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #666666; font-style: italic;"># Lister les screen</span>
<span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #660033;">-ls</span>
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-gestion-des-splits">Gestion des splits</h2><br />

<br />
Autre fonctionnalité intéressante, vous pouvez diviser votre terminal en régions. C'est bien pratique lorsque vous êtes connecté en ssh sur un serveur, cela vous évite d'ouvrir un autre terminal et de vous connecter une seconde fois.<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;"># Diviser l'écran horizontalement</span>
Ctrl+A puis S
&nbsp;
<span style="color: #666666; font-style: italic;"># Diviser l'écran verticalement</span>
Ctrl + A puis <span style="color: #000000; font-weight: bold;">|</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Passer d'une région à l'autre</span>
Ctrl + A puis Tab
&nbsp;
<span style="color: #666666; font-style: italic;"># Démarrer le shell dans la nouvelle région</span>
Ctrl + A puis c
&nbsp;
<span style="color: #666666; font-style: italic;"># Fermer une région</span>
Ctrl + A puis X
&nbsp;
<span style="color: #666666; font-style: italic;"># Ne conserver que la région active</span>
Ctrl + A puis Q
&nbsp;
<span style="color: #666666; font-style: italic;"># Sauvegarder la disposition des régions</span>
Ctrl + A puis :
layout save default
&nbsp;</pre></pre></div></div><br />
<br />]]></description>
                <pubDate>Thu, 12 Oct 2023 09:21:28 +0200</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Créer un serveur DNS local]]></title>
                <link>https://geekrungis.fr/wiki/creer-un-serveur-dns-local</link>
                <guid>https://geekrungis.fr/wiki/creer-un-serveur-dns-local</guid>
                <description><![CDATA[Dans cet article, je vais vous expliquer l'intérêt et la méthode pour se faire un serveur DNS local.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-c-est-quoi-un-serveur-dns-e">C'est quoi un serveur DNS ?</h2><br />

<br />
Pour rappel, un serveur DNS (Domain Name Server) permet de faire correspondre des adresses avec des IP. Par exemple, lorsque vous tapez l'adresse <a href="https://google.fr">https://google.fr</a> dans votre navigateur, c'est un serveur DNS qui dit à votre navigateur d'aller sur 142.250.178.131. Essayez de taper directement cette IP dans votre navigateur vous verrez, vous arriverez sur google.fr.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-a-quoi-sert-un-serveur-dns-local">A quoi sert un serveur dns local</h2><br />

<br />
Si je reprend mon exemple plus haut, le serveur DNS qui vous donne l'IP de google.fr est un serveur basé ailleurs qui peut être clouflare, google ou bien d'autres, il existe pas mal de serveurs DNS. Le choix du serveur peut se faire sur votre box mais il y a un paramétrage par défaut et on n'a pas forcément besoin d'y toucher.<br />
<br />
Mais ces fournisseurs de DNS ne savent pas que sur votre réseau local, votre jeedom est sur l'IP 192.168.21.25 ou que votre serveur plex est sur 192.168.21.32. C'est là qu'intervient le serveur DNS local. Vous allez pouvoir ajouter dans ce dernier la résolution des nom d'hôtes locaux.<br />
Au lieu de taper 192.168.21.25 dans votre navigateur pour atteindre votre jeedom, vous pourrez taper jeedom.domainelocal.lan par exemple.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-installation-et-configuration-du-serveur-dns">Installation et configuration du serveur DNS</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-installation">Installation</h3><br />

<br />
Je vous donne l'exmple sur une base Debian mais les autres distribution proposent le même paquet dnsmasq<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">apt <span style="color: #c20cb9; font-weight: bold;">install</span> dnsmasq</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-configuration">Configuration</h3><br />

<br />
Pour la configuration, il y a plusieurs fichiers à éditer :<br />
- dnsmasq.conf<br />
- dnsmasq-dns.conf<br />
- dnsmasq-hosts.conf<br />
<br />
Tous ces fichiers se trouvent dans /etc/.<br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-dnsmasq-conf">dnsmasq.conf</h4><br />

<br />
Ici, c'est la configuration générale.<br />
La seule ligne à modifier est la ligne qui commence par domain, c'est ici que vous mettez votre domaine local, par exmple :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">domain</span>=domainelocal.lan</pre></pre></div></div><br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-dnsmasq-dns-conf">dnsmasq-dns.conf</h4><br />

<br />
Dans ce fichier, vous allez mettre le ou les serveurs DNS externe sur lesquels vous souhaitez aller.<br />
Personnellement, j'ai choisi les serveurs DNS de CloudFlare, pour cela il suffit de supprimer les lignes existantes et d'ajouter celles-ci :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
nameserver 1.1.1.1
nameserver 1.0.0.1
&nbsp;</pre></pre></div></div><br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-dnsmasq-hosts-conf">dnsmasq-hosts.conf</h4><br />

<br />
C'est ici le fichier pour lequel nous avons installer un serveur DNS local, on va pouvoir y ajouter les machines locales avec leurs IP et le nom qu'on souhaite leur donner, par exemple, vous pouvez y ajouter les lignes suivantes à adapter :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
192.168.21.25     jeedom
192.168.21.32     plex
&nbsp;</pre></pre></div></div><br />
<br />
Ensuite, on relance le serveur DNS pour que nos paramètres soient pris en compte :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">systemctl restart dnsmasq.service</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-on-teste-e">On teste ?</h2><br />

<br />
Et là, on teste dans notre navigateur favori en tapant jeedom.domainelocal.lan et cela ne fonctionne pas !<br />
Et bien oui c'est normal...<br />
<br />
Petit rappel, lorsque vous connectez votre ordinateur ou n'importe quel périphérique au réseau on a deux possibilités :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> Entrer manuelle l'adresse IP ainsi que la passerelle et le serveur DNS
    </li><li class="formatter-li"> Laissez le serveur DHCP s'en occuper<br />
</li></ul><br />
<br />
Cela signifie donc que soit vous devez modifier le serveur DNS dans la configuration de votre client si vous spécifiez manuellement les informations réseau, soit configurer votre serveur DHCP pour que ce dernier envoi la bonne information.<br />
<br />
Je vous renvoi donc vers mon article sur la mise en place d'un serveur DHCP pour faire cela (<a href="https://geekrungis.fr/wiki/installer-et-parametrer-un-serveur-dhcp">Installer et paramétrer un serveur DHCP</a>). Si vous n'avez pas de serveur DHCP monté vous même, rendez dans l'interface de gestion de votre box, vous trouverez un menu permettant de modifier le serveur DNS utilisé, par exemple sur une freebox, dans paramètres puis DHCP :<br />
<br />
<p style="text-align: center;"><img src="https://geekrungis.fr/upload/freebox_dhcp.png" alt="freebox_dhcp" title="freebox_dhcp" /></p><br />
<br />
Vous pouvez modifier l'adresse dans serveur DNS 1 et mettre l'adresse IP de votre nouveau serveur DNS. Lorsqu'une machine demandera une adresse IP au serveur DHCP de votre box, cette dernière renverra l'adresse IP mais aussi le serveur DNS à utiliser.<br />
<br />
Une dernière chose, n'hésitez pas à aller consulter mon article sur quelques commandes réseau, vous y retrouverez notamment comment vérifier l'adresse du serveur DNS utilisé par un client, cela vous permettra de vérifier que c'est bien votre serveur DNS local qui répond aux requêtes : <a href="https://geekrungis.fr/wiki/quelques-commandes-reseau">Quelques commandes réseau</a><br />
<br />]]></description>
                <pubDate>Thu, 16 Mar 2023 10:46:37 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Supprimer automatiquement des anciens fichiers]]></title>
                <link>https://geekrungis.fr/wiki/supprimer-automatiquement-des-anciens-fichiers</link>
                <guid>https://geekrungis.fr/wiki/supprimer-automatiquement-des-anciens-fichiers</guid>
                <description><![CDATA[Aujourd'hui, un petit tuto rapide pour nettoyer automatiquement des fichiers anciens.<br />
<br />
Le contexte de ce tuto est le suivant : j'ai chez moi des caméras de surveillance qui n'enregistraient que lors de déclenchements d'alarmes. Je me suis dit qu'il serait préférable d'enregistrer les vidéos en continu. Bien entendu, cela pose rapidement un problème de place sur mes disques durs puisque mes caméra produisent environ 400 Go de vidéo par semaine...<br />
<br />
La méthode est assez simple :<br />
<br />
<ol class="formatter-ol">
    <li class="formatter-li"> Première étape : créer un script pour supprimer ces anciennes vidéos, je suis parti sur une période de 10 jours (les vidéos de plus de 10 jours seront supprimées par le script). Pour cela on crée un script bash avec son éditeur préféré sur le PC ou le serveur où sont stockées les fichiers en question, voici le code dans le mien :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #007800;">DUREE_RETENTION_EN_JOURS</span>=<span style="color: #000000;">10</span>
<span style="color: #007800;">CHEMIN_DOSSIER_VIDEOS</span>=<span style="color: #ff0000;">"/chemin_vers_le_dossier_des_videos/"</span>
<span style="color: #007800;">INAME_CONDITION</span>=<span style="color: #ff0000;">"*.mkv"</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #ff0000;">"<span style="color: #007800;">$CHEMIN_DOSSIER_VIDEOS</span>"</span> <span style="color: #660033;">-iname</span> <span style="color: #007800;">$INAME_CONDITION</span> <span style="color: #660033;">-ctime</span> +<span style="color: #007800;">$DUREE_RETENTION_EN_JOURS</span> <span style="color: #660033;">-delete</span>
&nbsp;</pre></pre></div></div><br />
<br />
Ce script va donc supprimer tous les fichiers .mkv dans le dossier choisi (et ses sous-dossiers) qui ont été modifiés il y a plus de 10 jours.
    </li><li class="formatter-li"> On n'oublie pas de rendre le script exécutable<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>mon_script.sh
&nbsp;</pre></pre></div></div>
    </li><li class="formatter-li"> On ajoute l'exécution du script dans le planificateur en ouvrant crontab<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
crontab <span style="color: #660033;">-e</span>
&nbsp;</pre></pre></div></div><br />
<br />
On ajoute ensuite la ligne qui va bien :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>bash<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">"/chemin/mon_script.sh"</span></pre></pre></div></div><br />
<br />
Mon script s'exécutera donc tous les matins à 5 heures.<br />
<br />
</li></ol>]]></description>
                <pubDate>Wed, 15 Mar 2023 15:51:34 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Migration de debian 10 vers debian 11 sur un raspberry]]></title>
                <link>https://geekrungis.fr/wiki/migration-de-debian-10-vers-debian-11-sur-un-raspberry</link>
                <guid>https://geekrungis.fr/wiki/migration-de-debian-10-vers-debian-11-sur-un-raspberry</guid>
                <description><![CDATA[Salut à tous, un petit article rapide pour décrire la méthode de migration de debian 10 (buster) vers debian 11 (bullseye) sur un raspberry et surtout comment résoudre le problème de DHCP.<br />
<br />
<span class="message-helper warning">Attention, vous devrez avoir un accès à votre raspberry avec écran et clavier après la mise à jour pour résoudre le problème de DHCP. Après la mise à jour, le raspberry n'a plus accès au réseau</span><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-sauvegarde">Sauvegarde</h2><br />

<br />
Avant toute chose, je vous conseille de faire une sauvegarde de votre système. Il existe plusieurs, méthode, la plus simple me semble être la suivante :<br />
<br />
<ol class="formatter-ol">
    <li class="formatter-li">retirer la carte SD (ou le disque dur SSD branché en USB) sur lequel le système est installé puis branchez le à un système linux
    </li><li class="formatter-li">cherchez l'identifiant du disque avec la commande :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">lsblk</pre></pre></div></div><br />
Dans mon cas, c'est /dev/sdc
    </li><li class="formatter-li">Exécutez la commande suivante pour créer une image du disque :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>remi<span style="color: #000000; font-weight: bold;">/</span>image_carte_sd.img</pre></pre></div></div><br />
</li></ol><br />
Cela va créer une image de votre carte SD (ou de votre disque dur) que vous pourrez restaurer en cas de besoin.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-migration-de-debian-10-vers-debian-11">Migration de debian 10 vers debian 11</h2><br />

<br />
Pour la migration, c'est assez simple, c'est comme une debian classique.<br />
<br />
Ouvrez le fichier de configuration des dépôts :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></pre></div></div><br />
<br />
remplacez "buster" par "bullseye" sur toutes les lignes de dépôt.<br />
<br />
Il faut également le faire dans tous les fichiers qui se trouvent dans /etc/apt/sources.list.d.<br />
<br />
Ensuite, il suffit de faire la mise à jour classique :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> apt update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> apt upgrade
&nbsp;</pre></pre></div></div><br />
<br />
Cela prend un peu de temps et c'est interactif, il y aura quelques questions auxquelles répondre.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-resolution-du-probleme-de-dhcp">Résolution du problème de DHCP</h2><br />

<br />
Lorsque vous redémarrerez le système, vous aurez une erreur :<br />
<br />
[<span style="color:#FF0000;">FAILED</span>] Failed to start DHCP Client Daemon.<br />
<br />
Pour le résoudre, il faut se loguer puis taper la commande suivante :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> raspi-config</pre></pre></div></div><br />
<br />
Vous allez ensuite dans :<br />
<ul class="formatter-ul">
    <li class="formatter-li">6 Advanced Options
    </li><li class="formatter-li">AA Network Config
    </li><li class="formatter-li">1 dhcpd<br />
</li></ul><br />
Vous pouvez redémarrer le rasberry, il devrait normalement se reconnecter au réseau normalement.]]></description>
                <pubDate>Fri, 03 Mar 2023 18:22:38 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Sauvegarde distante sur un disque dur externe chiffré]]></title>
                <link>https://geekrungis.fr/wiki/sauvegarde-distante-sur-un-disque-dur-externe-chiffre</link>
                <guid>https://geekrungis.fr/wiki/sauvegarde-distante-sur-un-disque-dur-externe-chiffre</guid>
                <description><![CDATA[Aujourd'hui, un petit article sur la mise en place d'une sauvegarde "distante" de ses fichiers sur un disque dur externe chiffré branché sur un raspberry.<br />
Je vais vous décrire cela sur un disque dur que j'ai à la maison, mais je l'ai autrefois fait sur un disque dur installé chez quelqu'un, cela fonctionne aussi. Il est juste nécessaire dans ce cas que la personne chez qui vous déposez le raspberry ait une ip fixe ou un nom de domaine et de rediriger les ports qui vont bien vers le raspberry.<br />
<br />
Comme souvent, la majorité des commandes sont à faire en root ou avec sudo.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-etape-1-acces-ssh-sans-mot-de-passe">Etape 1 : accès SSH sans mot de passe</h2><br />

<br />
Je ne vais pas vous redécrire l'opération, vous trouverez cela facilement sur internet, j'ai également un article en cours de rédaction sur le sujet.<br />
C'est important pour automatiser la sauvegarde.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-etape-2-la-creation-du-volume-chiffre-sur-son-disque-dur-externe">Etape 2 : La création du volume chiffré sur son disque dur externe</h2><br />

<br />
Rendez-vous sur le raspberry où est branché votre disque dur externe, ou bien vous pouvez brancher le disque dur sur votre ordinateur.<br />
Il sera nécessaire de supprimer les données du disque ou au moins de la partition que l'on veut chiffrer.<br />
<br />
Il est d'abord nécessaire d'installer cryptsetup si ce n'est pas le cas, exemple sur une debian :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">apt <span style="color: #c20cb9; font-weight: bold;">install</span> cryptsetup</pre></pre></div></div><br />
<br />
On cherche notre disque dur :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">lsblk</pre></pre></div></div><br />
<br />
On créé la partition qui sera chiffrée ensuite sur le disque trouvé (attention à ne pas se tromper de disque) :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cfdisk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda</pre></pre></div></div><br />
<br />
Vous arriverez sur l'interface de cfdisk qui vous permettra de supprimer la ou les partitions que vous souhaitez puis d'en créer une nouvelle à chiffrer.<br />
On ne formate pas la partition nouvellement créée.<br />
<br />
On chiffre la nouvelle partition :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsetup <span style="color: #660033;">--verify-passphrase</span> luksFormat <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1</pre></pre></div></div><br />
<br />
Cherchez dans le manuel de cryptsetup mais on peut spécifier des paramètres :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsetup <span style="color: #660033;">--verify-passphrase</span> <span style="color: #660033;">--cipher</span> serpent-cbc-essiv:sha256 <span style="color: #660033;">--key-size</span> <span style="color: #000000;">256</span> luksFormat <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1</pre></pre></div></div><br />
<br />
On vous demandera confirmation pour effacer les données et d'entrer votre nouvelle passphrase (deux fois).<br />
<br />
On ouvre ensuite le conteneur en lui donnant un nom (ici, je l'appelle cryptWD, on pourra le changer à chaque fois qu'on l'ouvrira) :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsetup luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1 cryptWD</pre></pre></div></div><br />
<br />
La partition sera alors accessible via /dev/mapper/cryptWD<br />
<br />
Il suffit ensuite de formater la partition :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">mkfs.ext4 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptWD</pre></pre></div></div><br />
<br />
Enfin, on monte la partition :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptWD <span style="color: #000000; font-weight: bold;">/</span>mnt </pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-etape-3-automatisation-de-l-ouverture-du-conteneur">Etape 3 : Automatisation de l'ouverture du conteneur</h2><br />

<br />
Nous avons créé notre conteneur et vu comment l'ouvrir puis le monter.<br />
Pour automatiser l'ouverture et le montage, rendez-vous sur <a href="https://geekrungis.fr/wiki/montage-d-un-volume-crypte-au-demarrage-du-systeme">cet article</a> qui décrit toute la démarche.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-etape-4-la-sauvegarde">Etape 4 : La sauvegarde</h2><br />

<br />
Tout est en place maintenant pour faire la sauvegarde :<br />
<ul class="formatter-ul">
    <li class="formatter-li">notre disque dur contient une partition chiffrée qui s'ouvre et se monte automatiquement au démarrage du système
    </li><li class="formatter-li">nous avons accès à notre système distant sans mot de passe<br />
</li></ul><br />
<br />
Nous allons maintenant passer au script de sauvegarde.<br />
Je vous mets en exemple, le script bash que j'utilise. Il est à adapter :<br />
<ul class="formatter-ul">
    <li class="formatter-li">SOURCE >> les fichiers à sauvegarder
    </li><li class="formatter-li">LOGFILE >> où vous sauvegarder les logs de la sauvegarde
    </li><li class="formatter-li">SERVDEST >> ip de mon raspberry où est branché le disque dur chiffré<br />
</li></ul><br />
<br />
J'ai crée une fonction pour chaque dossier, cela me permet de bien séparer les choses et d'en ajouter ou supprimer facilement.<br />
<br />
Mon fichier exclusions_rsync.txt contient les lignes suivantes :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
.recycle
<span style="color: #000000; font-weight: bold;">@</span>Recycle
.Trash
&nbsp;
&nbsp;</pre></pre></div></div><br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#Variables</span>
<span style="color: #007800;">PORT</span>=<span style="color: #000000;">22</span>
<span style="color: #007800;">EXCLUDEFILE</span>=<span style="color: #ff0000;">"/srv/mergerfs/DATA/Informatique/Backups/Rsync_RPI/exclusions_rsync.txt"</span>
<span style="color: #007800;">DATEFICHIER</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y.<span style="color: #000000; font-weight: bold;">%</span>m.<span style="color: #000000; font-weight: bold;">%</span>d_<span style="color: #000000; font-weight: bold;">%</span>H.<span style="color: #000000; font-weight: bold;">%</span>M.<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">LOGFILE</span>=<span style="color: #ff0000;">"/srv/mergerfs/DATA/Informatique/Backups/Rsync_RPI/logs/rsync_<span style="color: #007800;">$DATEFICHIER</span>.log"</span>
<span style="color: #007800;">SOURCE</span>=<span style="color: #ff0000;">"/srv/mergerfs/DATA/"</span>
<span style="color: #007800;">USER</span>=<span style="color: #ff0000;">"user"</span>
<span style="color: #007800;">SERVDEST</span>=<span style="color: #ff0000;">"192.168.1.51"</span>
<span style="color: #007800;">PATHDEST</span>=<span style="color: #ff0000;">"/mnt/cryptWD/"</span>
<span style="color: #007800;">OPTIONS</span>=<span style="color: #ff0000;">"-ah --ignore-existing --info=MISC2,PROGRESS2,STATS2 --exclude-from=<span style="color: #007800;">$EXCLUDEFILE</span> --log-file=<span style="color: #007800;">$LOGFILE</span> --log-file-format="</span>
<span style="color: #007800;">DATEDEBUT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y.<span style="color: #000000; font-weight: bold;">%</span>m.<span style="color: #000000; font-weight: bold;">%</span>d_<span style="color: #000000; font-weight: bold;">%</span>H.<span style="color: #000000; font-weight: bold;">%</span>M.<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
DebutFichier<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Début de la sauvegarde - <span style="color: #007800;">$DATEDEBUT</span>"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeHomes<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Homes"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Homes/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Homes/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeInformatique<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Informatique"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Informatique/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Informatique/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeLivres<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Livres"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Livres/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Livres/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeMusique<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Musique"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Musique/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Musique/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardePhotos<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Photos"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Photos/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Photos/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardePublic<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Public"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Public/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Public/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeTelechargements<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Telechargements"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Telechargements/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Telechargements/"</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">""</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
SauvegardeVideos<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Sauvegarde du dossier Videos"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
    rsync <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p <span style="color: #007800;">$PORT</span>"</span> <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$SOURCE</span><span style="color: #ff0000;">"Videos/"</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$SERVDEST</span>:<span style="color: #007800;">$PATHDEST</span><span style="color: #ff0000;">"Videos/"</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
FinFichier<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">DATEFIN</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y.<span style="color: #000000; font-weight: bold;">%</span>m.<span style="color: #000000; font-weight: bold;">%</span>d_<span style="color: #000000; font-weight: bold;">%</span>H.<span style="color: #000000; font-weight: bold;">%</span>M.<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Fin de la sauvegarde - <span style="color: #007800;">$DATEFIN</span>"</span> <span style="color: #000000; font-weight: bold;">>></span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
EnvoiMail<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"La sauvegarde s'est terminée"</span> <span style="color: #000000; font-weight: bold;">|</span> mutt <span style="color: #660033;">-s</span> <span style="color: #ff0000;">"Sauvegarde réussie"</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$LOGFILE</span> <span style="color: #660033;">--</span> adressemail<span style="color: #000000; font-weight: bold;">@</span>fournisseur.fr
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
main<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
    DebutFichier
    SauvegardeHomes
    SauvegardeInformatique
    SauvegardeLivres
    SauvegardeMusique
    SauvegardePhotos
    SauvegardePublic
    SauvegardeTelechargements
    SauvegardeVideos
    FinFichier
    EnvoiMail
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
main
&nbsp;</pre></pre></div></div><br />
<br />
<br />
Il vous suffit ensuite de tester le script avant de passer à l'étape suivante.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-planification-de-la-sauvegarde">Planification de la sauvegarde</h2><br />

<br />
Enfin, on planifie la sauvegarde avec un petit crontab -e et on ajoute la ligne qui va bien, pour mon exemple :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">30</span> <span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">7</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">/</span>srv<span style="color: #000000; font-weight: bold;">/</span>mergerfs<span style="color: #000000; font-weight: bold;">/</span>DATA<span style="color: #000000; font-weight: bold;">/</span>Informatique<span style="color: #000000; font-weight: bold;">/</span>Backups<span style="color: #000000; font-weight: bold;">/</span>Rsync_RPI<span style="color: #000000; font-weight: bold;">/</span>sauvegarde.sh</pre></pre></div></div><br />
<br />
Me permet de faire ma sauvegarde toutes les semaines le lundi matin à 3h30.<br />
<br />]]></description>
                <pubDate>Thu, 02 Mar 2023 18:08:28 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Montage d'un volume crypté au démarrage du système]]></title>
                <link>https://geekrungis.fr/wiki/montage-d-un-volume-crypte-au-demarrage-du-systeme</link>
                <guid>https://geekrungis.fr/wiki/montage-d-un-volume-crypte-au-demarrage-du-systeme</guid>
                <description><![CDATA[Dans cet article, nous allons voir comment monter manuellement puis automatiquement un système de fichier crypté avec luks.<br />
Toutes les commandes se font en root (ou avec sudo).<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-creation-d-une-cle">Création d'une clé</h2><br />

<br />
Cette clé permet d'ouvrir un conteneur luks sans avoir à entrer de mot de passe.<br />
On va créer une clé aléatoire à l'aide de la commande suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.keyfile_luks <span style="color: #007800;">bs</span>=<span style="color: #000000;">1024</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">4</span></pre></pre></div></div><br />
<br />
On rend ensuite cette clé illisible pour le commun des mortels :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">400</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.keyfile_luks</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-association-de-la-cle-au-conteneur">Association de la clé au conteneur</h2><br />

<br />
On associe ensuite cette clé au conteneur luks :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsetup luksAddKey <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>datavg-sauvegardelv <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.keyfile_luks</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-test-de-la-cle">Test de la clé</h2><br />

<br />
On peut ensuite tester l'ouverture manuelle du conteneur à l'aide de cette clé :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsetup <span style="color: #660033;">--key-file</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.keyfile_luks luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>datavg-sauvegardelv cryptsauvegarde</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-montage-du-conteneur">Montage du conteneur</h2><br />

<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptsauvegarde <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>cryptWD</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-tout-en-une-commande">Tout en une commande</h2><br />

<br />
On peut également ouvrir le conteneur et monter le système de fichier en une commande :<br />
<br />
cryptsetup --key-file /root/.keyfile_luks luksOpen /dev/mapper/datavg-sauvegardelv cryptsauvegarde && wait && mount /dev/mapper/cryptsauvegarde /mnt/cryptWD<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-automatisation">Automatisation</h2><br />

<br />
On va maintenant automatiser cette manip. au démarrage du système via fstab et crypttab<br />
<br />
A l'instar du fichier fstab qui automatise les montages de partitions, crypttab automatise l'ouverture de conteneurs sécurisés.<br />
On modifie le fichier /etc/crypttab en ajoutant la ligne suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">nom_du_conteneur_ouvert       chemin_vers_le_conteneur        chemin_vers_le_fichier_de_clé</pre></pre></div></div><br />
<br />
Dans mon cas, pour exemple :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">cryptsauvegarde       <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>datavg-sauvegardelv       <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.keyfile_luks</pre></pre></div></div><br />
<br />
Ensuite, on modifier le fichier fstab en aoutant la ligne suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">chemin_conteneur_ouvert     point_de_montage       <span style="color: #7a0874; font-weight: bold;">type</span>        options        <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span></pre></pre></div></div><br />
<br />
Par exemple, dans mon cas :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptsauvegarde     <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>cryptWD       ext4       defaults       <span style="color: #000000;">0</span>        <span style="color: #000000;">0</span></pre></pre></div></div><br />
<br />
Vous pouvez rebooter et vérifier que cela fonctionne !]]></description>
                <pubDate>Thu, 02 Mar 2023 17:42:33 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Mémo git]]></title>
                <link>https://geekrungis.fr/wiki/memo-git</link>
                <guid>https://geekrungis.fr/wiki/memo-git</guid>
                <description><![CDATA[Ici, juste un article me permettant de garder mémoire des commandes utiles (pour moi) sur git. Je n'utilise que peu git et cet outil permet tellement de choses qu'il est parfois complexe de s'y retrouver.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-en-local">En local</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-initier-le-projet">Initier le projet</h3><br />

<br />
On se place dans le dossier que l'on veut "giter" :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">git init</span>                <span style="color: #666666; font-style: italic;"># initie un dépôt vide et créé les fichiers nécessaires</span>
<span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #660033;">--all</span>           <span style="color: #666666; font-style: italic;"># ajoute tous les fichiers du dossier dans l'index du dépôt </span>
<span style="color: #c20cb9; font-weight: bold;">git commit</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">"test"</span>    <span style="color: #666666; font-style: italic;"># enregistre les changements dans le dépôt. L'option -m ajoute un message (explication des modif. par exemple)</span>
&nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-ignorer-des-fichiers">Ignorer des fichiers</h3><br />

<br />
Il existe différentes méthodes pour ignorer des fichiers. La plus simple et la plus connue reste l'utilisation du fichier .gitignore placé à la racine du dépôt.<br />
<br />
On y ajoute ensuite les fichiers/dossiers qu'on veut ignorer. Cela peut être des noms de fichiers, de dossiers, des chemins, on peut utiliser aussi l'étoile.<br />
<br />
Si on souhaite supprimer des fichiers qu'on a publié et qu'on ajoute au .gitignore :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rm</span> <span style="color: #660033;">--cached</span> filename</pre></pre></div></div><br />
<br />
L'option --cached indique à git de ne pas supprimer le fichier de l'arborescence de travail mais seulement de le supprimer de l'index.<br />
Avec un dossier, de manière récursive, on ajoute l'option -r :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rm</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">--cached</span> directory</pre></pre></div></div><br />
<br />
On peut faire un check avec l'option -n<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git rm</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">--cached</span> directory</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-gestion-des-branches">Gestion des branches</h3><br />

<br />
Pour créer une nouvelle branche :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git branch</span> dev       <span style="color: #666666; font-style: italic;"># créé une branche nommée dev</span></pre></pre></div></div><br />
<br />
Pour lister les branches :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git branch</span> <span style="color: #660033;">--list</span></pre></pre></div></div><br />
<br />
Pour supprimer une branche :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git branch</span> <span style="color: #660033;">-d</span> dev       <span style="color: #666666; font-style: italic;"># supprime la branche dev</span></pre></pre></div></div><br />
<br />
Pour renommer une branche :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git branch</span> <span style="color: #660033;">-m</span> dev tests    <span style="color: #666666; font-style: italic;"># renomme la branche dev en tests</span></pre></pre></div></div><br />
<br />
Pour basculer sur une branche :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git checkout</span> dev</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-le-remisage-git-stash">Le remisage (git stash)</h3><br />

<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-les-differentes-commandes-git-stash">Les différentes commandes git stash</h4><br />

<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span></pre></pre></div></div><br />
<br />
La commande git stash permet de remiser ("mettre de côté") des développements pour faire une petite modification et la "commiter" avant de reprendre ces développements mais sans les avoir commités. On peut en effet voir avec la commande git status après un git stash qu'il n'y a plus de modification à commiter.<br />
<br />
La commande suivante permet de vérifier ce qui est remisé :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> list</pre></pre></div></div><br />
<br />
Pour être plus précis et commenté ce qu'on a remisé :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> save commentaire même en plusieurs mots sans guillements</pre></pre></div></div><br />
<br />
Pour avoir des détails sur une remise :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> show stash<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>             <span style="color: #666666; font-style: italic;"># stash@{1} est le nom du stash visible avec la commande list</span></pre></pre></div></div><br />
<br />
Encore plus de détails :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> show stash<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #660033;">-p</span></pre></pre></div></div><br />
<br />
<span class="message-helper notice">Il est possible de faire plusieurs stash</span><br />
<br />
Pour reprendre le travail remisé et l'appliquer au commit courant :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> apply</pre></pre></div></div><br />
<br />
ou pour spécifier le stash si on en a plusieurs :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> apply stash<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></pre></div></div><br />
<br />
<span class="message-helper notice">Les modifications remisées le sont toujours après la commande précédente même si elles ont été importées dans le commit courant. Pour les supprimer : <div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> drop</pre></pre></div></div><br />
On peut également tout faire en une commande (apply + drop) avec la commande :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> pop stash<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></pre></div></div><br />
</span><br />
<br />
Par défaut, git stash ne prend pas en compte les nouveaux fichiers. Pour les prendre en compte :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git stash</span> <span style="color: #660033;">-u</span></pre></pre></div></div><br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-exemple-de-mise-en-pratique">Exemple de mise en pratique</h4><br />

<br />
Prenons un exemple qui m'est arrivé. J'ai une branche main, en prod et publiée sur GitHub, avec un fichier index.html. Pour faire de nouveaux développements, je créé une branche dev. Je fais des développements sans connaitre la fonction git stash :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> Je fais des modifications dans index.html
    </li><li class="formatter-li"> Je créé un fichier style.css
    </li><li class="formatter-li"> Je créé un fichier background.png<br />
</li></ul><br />
<br />
Je voudrais commiter puis publier les modifications d'index.html dans la branche main car j'ai corrigé une erreur mais sans commiter le reste.<br />
<br />
C'est parti !<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">git</span> restore <span style="color: #660033;">--staged</span> style.css background.png          <span style="color: #666666; font-style: italic;"># à faire seulement si ils sont indexés, on peut le vérifier avec git status</span>
<span style="color: #c20cb9; font-weight: bold;">git commit</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">"modification d'index.html"</span>              <span style="color: #666666; font-style: italic;"># pour commiter ma modification d'index.html</span>
<span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #660033;">--all</span>                                          <span style="color: #666666; font-style: italic;"># pour indexer mes fichiers avant des les remiser</span>
<span style="color: #c20cb9; font-weight: bold;">git stash</span> save nouveaux fichiers                      <span style="color: #666666; font-style: italic;"># pour remiser mes deux nouveaux fichiers avant de changer de branche</span>
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> main                                      <span style="color: #666666; font-style: italic;"># pour rebasculer sur la branche main</span>
<span style="color: #c20cb9; font-weight: bold;">git merge</span> dev                                         <span style="color: #666666; font-style: italic;"># pour intégrer les modifications d'index.html présentes dans la branche dev dans la branche main</span>
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> dev                                       <span style="color: #666666; font-style: italic;"># pour retourner sur la branche dev</span>
<span style="color: #c20cb9; font-weight: bold;">git stash</span> apply                                        <span style="color: #666666; font-style: italic;"># pour récupérer mes deux fichiers remisés</span>
<span style="color: #c20cb9; font-weight: bold;">git stash</span> drop                                         <span style="color: #666666; font-style: italic;"># pour supprimer mon stash</span>
<span style="color: #c20cb9; font-weight: bold;">git add</span> <span style="color: #660033;">--all</span>                                          <span style="color: #666666; font-style: italic;"># pour réindexer ces fichiers</span>
&nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-la-commande-git-log">La commande git log</h3><br />

<br />
La commande git-log permet de voir l'historique des commit.<br />
La plus courante, renvoit une liste de commits, avec leurs identifiants :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git log</span> <span style="color: #660033;">--oneline</span></pre></pre></div></div><br />
<br />
Quelques options complémentaires utiles :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> --name-status liste les fichiers créés, modifiés ou supprimés pour chaque commit
    </li><li class="formatter-li"> -n 2 ou -2 ou --max-count=2 limite le nombre de commits affichés à 2
    </li><li class="formatter-li"> --skip=3 n'affichera pas les 3 derniers commits
        </li><li class="formatter-li"> --berfore=MM/JJ/AAAA limite aux commits avant la date donnée (attention au format)
        </li><li class="formatter-li"> --after=MM/JJ/AAAA limite aux commits après la date donnée<br />
</li></ul><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-la-commande-git-reset">La commande git reset</h3><br />

<br />
<span class="message-helper warning">La commande git reset va affecter l'historique en supprimant des commits !</span><br />
<br />
La commande git reset permet de revenir en arrière sur les commits.<br />
Tout d'abord, il faut connaitre l'identifiant du commit voulu (voir ci-dessus la commande git log).<br />
<br />
Ensuite la commande de base, va permettre de revenir en arrière en supprimant les commits suivants mais en conservant la modification des fichiers. Les fichiers seront alors en statut non stagé :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git reset</span> 5fb06a6           <span style="color: #666666; font-style: italic;"># 5fb06a6 est le numéro du commit</span></pre></pre></div></div><br />
<br />
Il existe plusieurs modes de fonctionnement de la commande git reset, j'en présente 3 ici :<br />
<br />
<ul class="formatter-ul">
    <li class="formatter-li"> --mixed [valeur par défaut] se comporte comme décrit ci-dessus.
    </li><li class="formatter-li"> --soft se comporte comme ci-dessus sauf que les fichiers seront stagged
    </li><li class="formatter-li"> --hard ne conserve pas la modification des fichiers. <strong><span style="text-decoration: underline;">Attention !</span></strong><br />
</li></ul><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-depot-distant">Dépôt distant</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-parametrer-les-connexion-au-depot-distant">Paramétrer les connexion au dépôt distant</h3><br />

<br />
Il est aussi possible de passer directement via CLI sans token mais cela nécessite l'installation de GitHub qui n'est pas dans les dépôts officiels de Debian ou autres distributions. Je trouve les méthodes via token et SSH bien mieux.<br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-via-https-via-un-token">Via HTTPS (Via un token)</h4><br />

<br />
Pour générer un token, il faut se rendre sur son compte GitHub, cliquer sur son image en haut à droite puis Settings.<br />
Cliquer ensuite tout en bas à gauche sur Developer settings puis Personnal access tokens et Tokens (classic).<br />
Cliquer ensuite sur Generate new token puis Generate new token (classic).<br />
<br />
Dans cette fenêtre, on peut paramétrer les accès et la date d'expiration du token. Une fois rempli, cliquer en bas sur Generate token.<br />
<br />
La clé est générée et affichée. Elle sert de mot de passe à la place du mot de passe utilisateur dans la commande git push (<a href="https://geekrungis.fr/wiki/memo-git#git-push">voir plus bas dans l'article</a>)<br />
<br />
<img src="https://geekrungis.fr/upload/github_token.png" alt="github_token" title="github_token" /><br />
<br />
<span class="message-helper warning">Attention à bien copier cette clé car on ne peut la retrouver ensuite</span><br />
<br />
<h4 class="formatter-title wiki-paragraph-4" id="paragraph-avec-une-cle-ssh">Avec une clé SSH</h4><br />

<br />
Pour cela, il est nécessaire :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> d'avoir une paire de clé (privée/publique)
    </li><li class="formatter-li"> de déposer sa clé publique sur son compte github
    </li><li class="formatter-li"> d'activer ssh-agent sur son poste local<br />
</li></ul><br />
<br />
<h5 class="formatter-title wiki-paragraph-5" id="paragraph-generer-sa-paire-de-cle">Générer sa paire de clé</h5><br />

<br />
Pour cela, plein de tutos existent. Sinon, un petit tour sur mon article <a href="https://geekrungis.fr/wiki/ansible">Ansible</a> et c'est décrit.<br />
<br />
<h5 class="formatter-title wiki-paragraph-5" id="paragraph-deposer-sa-cle-sur-son-compte-github">Déposer sa clé sur son compte github</h5><br />

<br />
Pour cela, c'est très simple, on se rend sur compte Github, puis on clique sur l'icone en haut à droite puis settings.<br />
On va ensuite à gauche dans le menu SSH and GPG keys avant de cliquer sur le bouton vert "New SSH Key".<br />
<br />
On peut ensuite faire un copier/coller du texte contenu dans le fichier de clé publique (fichier.pub).<br />
<br />
<span class="message-helper warning">Attention à ne pas copier le contenu de sa clé privée !</span><br />
<br />
<h5 class="formatter-title wiki-paragraph-5" id="paragraph-activer-le-ssh-agent">Activer le ssh-agent</h5><br />

<br />
Il faut ensuite activer ssh-agent sur le poste local avec la commande suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #ff0000;">"<span style="color: #007800;">$(ssh-agent -s)</span>"</span>
<span style="color: #000000; font-weight: bold;">></span> Agent pid <span style="color: #000000;">59566</span></pre></pre></div></div><br />
<br />
puis ajouter sa clé à l'agent ssh :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-add</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_ed25519                 <span style="color: #666666; font-style: italic;"># id_ed25519 est le nom du fichier de clé privée</span></pre></pre></div></div><br />
<br />
<span class="message-helper notice">Si vous avez entrer une passphrase sur la clé (ce qui est fortement recommandé), elle sera demandée ici</span><br />
<br />
On peut ensuite tester la connexion à github avec la commande suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-T</span> <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com</pre></pre></div></div><br />
<br />
après avoir validé l'empreinte, vous devriez avoir un beau message de confirmation !<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-quelques-commandes-relatives-aux-depots-distants">Quelques commandes relatives aux dépôts distants</h3><br />

<br />
Pour ajouter un dépôt distant (dans lequel on publiera les fichiers) :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git remote</span> add origin UrlDépôtGit</pre></pre></div></div><br />
<br />
permet d'ajouter le dépôt distant défini par son url.<br />
<br />
<span id="git-push"></span><br />
<br />
<span class="message-helper warning">Cette URL peut varier en fonction de la méthode de publication :<br />
<ul class="formatter-ul">
    <li class="formatter-li"> Via un token, l'url est de la forme <a href="https://github.com/username/repository.git">https://github.com/username/repository.git</a>
    </li><li class="formatter-li"> Via SSH, l'url est de la forme git@github.com:username/repository.git<br />
</li></ul><br />
</span><br />
<br />
Pour publier les commits d'une nouvelle branche (qu'on a en local mais en distant) :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> <span style="color: #660033;">-u</span> origin main               <span style="color: #666666; font-style: italic;"># origin est le nom du dépôt distant et main le nom de la branche</span></pre></pre></div></div><br />
<br />
Pour publier les modifications de toutes les branches :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git push</span> <span style="color: #660033;">--all</span></pre></pre></div></div><br />
<br />
La commande suivante permet de voir quel dépôt distant est associé au dépôt local :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git remote</span> <span style="color: #660033;">-v</span></pre></pre></div></div><br />
<br />
<br />]]></description>
                <pubDate>Thu, 24 Nov 2022 10:10:10 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Ansible]]></title>
                <link>https://geekrungis.fr/wiki/ansible</link>
                <guid>https://geekrungis.fr/wiki/ansible</guid>
                <description><![CDATA[Ici, je vais noter ce que j'apprend sur Ansible et ce qui me semble pertinent.<br />
Peut-être que si cet article devient trop long, il sera plus tard divisé en plusieurs...<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-installation">Installation</h2><br />

<br />
Selon le site d'Ansible, il existe plusieurs méthodes :<br />
<ul class="formatter-ul">
    <li class="formatter-li">les binaires
    </li><li class="formatter-li">les dépôts (apt, dnf...)
    </li><li class="formatter-li">pip<br />
</li></ul><br />
J'ai commencé par installé via apt mais l'installation ne m'a pas créé de dossier /etc/ansible.<br />
J'ai donc essayé via la commande pip mais le résultat est identique.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-configuration-de-ssh">Configuration de ssh</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-utilisation-de-la-cle-privee">Utilisation de la clé privée</h3><br />

<br />
Il est nécessaire de pouvoir accéder en ssh à ses serveurs que l'on veut pouvoir gérer via ansible. Il faut pour cela utiliser la méthode de clé privée/publique. Rien de compliqué, plein de sites en parlent...<br />
<br />
Quelques rappels de commandes.<br />
<br />
Pour générer les clés :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> ecdsa <span style="color: #660033;">-b</span> <span style="color: #000000;">521</span></pre></pre></div></div><br />
<br />
Cette commande permet de générer une clé de type ecdsa avec la longueur maximale.<br />
La page de manuel de ssh-keygen donne des infos sur les différentes types et les longueurs de clé que l'on peut générer en fonction de la méthode choisie.<br />
<br />
Il est possible de générer une clé sans phrase de passe mais ce n'est pas le plus sécurisé...<br />
<br />
Pour copier la clé sur le serveur distant :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ssh-copy-id user<span style="color: #000000; font-weight: bold;">@</span>ip-serveur-distant <span style="color: #660033;">-p</span> port-serveur-ssh</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-utilisation-des-noms-d-hote">Utilisation des noms d'hôte</h3><br />

<br />
Afin de simplifier les choses, il est conseiller de bien configurer ssh pour que la connexion soit simplifiée.<br />
Pour cela, créer ou éditer le fichier ~/.ssh/config<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
Host rpi3
    HostName 192.168.1.51
    Port <span style="color: #000000;">7985</span>
    User pi
&nbsp;</pre></pre></div></div><br />
<br />
L'ajout de ce type de bloc dans le fichier permet de spécifier pour un nom d'hôte : l'adresse ip ou le hostname configuré en dns, le port si on n'utilise pas le port 22, le nom d'utilisateur.<br />
<br />
Dans le cas contraire, il sera nécessaire de configurer ces paramètres dans ansible via l'inventory.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-ansible-en-mode-cli">Ansible en mode "CLI"</h2><br />

<br />
On peut utiliser "manuellement" en ligne de commande.<br />
<br />
Par exemple:<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ansible transmission <span style="color: #660033;">-m</span> <span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-i</span> hosts.yaml <span style="color: #660033;">--key-file</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>remi<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>key_asus_fedora</pre></pre></div></div><br />
<br />
<ul class="formatter-ul">
    <li class="formatter-li">-i permet de spécifier le fichier d'inventaire à utiliser, de base il utilise le fichier /etc/ansible/hosts (où le fichier défini dans ansible.cfg, voir paragraphe dédié)
    </li><li class="formatter-li">-m permet d'appeler un module, ici le module ping
    </li><li class="formatter-li">transmission est l'hôte sur lequel on exécute la commande, défini dans le fichier d'inventaire
        </li><li class="formatter-li">--key-file permet de spécifier la clé privée à utiliser (cf. les notions après)
    </li><li class="formatter-li">-u permet de préciser l'utilisateur distant
    </li><li class="formatter-li">-b permet de passer les commandes avec une élévation de privilèges (par défaut avec sudo. Pour modifier, on peut utiliser le paramètre --become-method=su pour utiliser su plutôt que sudo)
    </li><li class="formatter-li">-k permet de demander le mot de passe de l'utilisateur (si on n'utilise pas la clé privée)
    </li><li class="formatter-li">-K permet de demander le mot de passe lié à l'élévation de privilège
    </li><li class="formatter-li">-C permet de tester la commande sans faire les actions
    </li><li class="formatter-li">-D permet de retourner les modifications effectuées<br />
</li></ul><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-quelques-notions-a-avoir-en-tete">Quelques notions à avoir en tête</h2><br />

<br />
Lorsqu'on exécute ansible, la connexion se fait avec l'utilisateur courant donc si la clé privée sur le serveur distant est celle de remi, lancer une commande ansible avec root ne fonctionne pas... Il faut alors spécifier manuellement la clé (avec l'option --key-file de la commande ansible<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-ansible-cfg">ansible.cfg</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-localisation-du-fichier">Localisation du fichier</h3><br />

<br />
ansible.cfg est le fichier de configuration d'ansible.<br />
<br />
Si celui-ci n'est pas présent dans /etc/Ansible/, il est possible de le générer via la commande :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ansible-config init <span style="color: #660033;">--disabled</span> <span style="color: #000000; font-weight: bold;">></span> ansible.cfg</pre></pre></div></div><br />
<br />
<span class="message-helper notice">Cette commande n'est valable que depuis ansible 2.12. Pour les versions antérieures, on peut aller chercher des exemples de fichier ansible.cfg sur le github du projet. Par exemple pour la version 2.10 : <a href="https://github.com/ansible/ansible/tree/stable-2.10">Github de la version 2.10</a></span><br />
<br />
Ce fichier gérera tout Ansible mais il est aussi possible de faire des fichiers plus spécifiques dans le dossier home (.Ansible/ansible.cfg) qui ne s'appliquera qu'à un utilisateur donné ou dans le dossier d'un playbook pour qu'il ne s'applique qu'à ce playbook.<br />
<br />
On peut dans ce fichier modifier la localisation du fichier hosts mais ce n'est pas conseillé (voir ci-après)<br />
<br />
Pour voir le fichier de configuration pris en compte, on peut utiliser la commande suivante :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ansible-config <span style="color: #660033;">--view</span></pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-quelques-parametres-interessants">Quelques paramètres intéressants </h3><br />

<br />
Voici quelques paramètres intéressants à modifier dans ansible.cfg :<br />
<br />
S'affranchir de la validation du fingerprint lors de la première connexion :<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>defaults<span style="color: #7a0874; font-weight: bold;">&#93;</span>
host-key-checking = <span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-l-inventory">L'inventory</h2><br />

<br />
Les inventory vont permettre de lister les serveurs cibles d'Ansible. On peut y spécifier notamment :<br />
<ul class="formatter-ul">
    <li class="formatter-li">Les hôtes (par IP ou pas hostname
    </li><li class="formatter-li">Les ports ssh des hôtes
    </li><li class="formatter-li">Les idées avec lesquels se connecter aux hôtes<br />
</li></ul><br />
<br />
<span class="message-helper warning">A vérifier : les users et port doivent-ils être défini dans les inventory ou la config ssh suffit-elle</span><br />
<br />
Le fichier inventory sera au format YAML, plus pratique (.yml ou .yaml).<br />
<br />
Exemple d'un fichier d'inventory :<br />
<br />
<div class="formatter-container formatter-code code-JSON"><span class="formatter-title">Code JSON : </span><div class="formatter-content"><pre style="display:inline;"><pre class="json" style="font-family:monospace;">&nbsp;
all:
  hosts:                      # en dessous, les serveurs directement rattachés à all
    srv1:                     # exemple d'un serveur appelé par son hostname
  children:                   # en dessous, des groupes enfants du groupe all
    debian:                   # exemple d'un groupe nommé debian
       hosts:                 # en dessous la liste des machines du groupe debian
          srv1:               # une machine nommée serv1
          srv[3-6]:           # les machines nommées serv3, serv4, serv5 et serv6
       vars:                  # en dessous les variables qui s'appliquent au groupe debian
          var1: "debian"      # une variable nommée var1 qui vaut "debian"
    ubuntu:                   # un groupe nommé Ubuntu
       hosts:
          srv8:
             vars:            # en dessous des variables qui ne s'appliquent qu'à la machine srv8
                var1: "Ubuntu"
          srv9:
          srv10:
       vars:                  # en dessous des variables qui s'appliquent à l'ensemble du groupe "Ubuntu"
          var1: "linux"
&nbsp;</pre></pre></div></div><br />
<br />
<span class="message-helper warning">On met ici comme exemple la possibilité de définir des variables dans l'inventory mais ce n'est pas le meilleur endroit où le faire. Il est préférable d'utiliser des dossiers group_vars et host_vars pour cela. On peut ensuite soit créer des fichier avec le nom des groupes soit des dossiers avec le nom des groupes puis un fichier avec les variables à l'intérieur du fichier</span><br />
<br />
Un fichier par groupe avec les variables à l'intérieur :<br />
<br />
├── 00_inventory.yml<br />
├── group_vars<br />
│   ├── debian.yml<br />
│   └── ubuntu.yml<br />
└── host_vars<br />
    └── srv8.yml<br />
<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-la-commande-ansible-inventory">La commande "ansible-inventory"</h3><br />

<br />
Cette commande permet d'afficher de différentes manières l'inventory.<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"> ansible-inventory <span style="color: #660033;">-i</span> inventory.yml <span style="color: #660033;">--list</span></pre></pre></div></div><br />
<br />
renverra l'inventaire avec -i le fichier d'inventaire. Voici la forme de restitution :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
{
    "_meta": {
        "hostvars": {
            "srv1": {
                "var1": "debian"
            },
            "srv10": {
                "var1": "linux"
            },
            "srv3": {
                "var1": "debian"
            },
            "srv4": {
                "var1": "debian"
            },
            "srv5": {
                "var1": "debian"
            },
            "srv6": {
                "var1": "debian"
            },
            "srv8": {
                "var1": "Ubuntu"
            },
            "srv9": {
                "var1": "linux"
            }
        }
    },
&nbsp;</pre></pre></div></div><br />
<br />
L'option --yaml permet d'afficher en format yml. Cela revient à afficher le fichier inventory.yml en y ajoutant les variables des group_vars et host_vars.<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
all:
  children:
    debian:
      hosts:
        srv1:
          var1: debian
        srv3:
          var1: debian
        srv4:
          var1: debian
        srv5:
          var1: debian
        srv6:
          var1: debian
    ubuntu:
      hosts:
        srv10:
          var1: linux
        srv8:
          var1: Ubuntu
        srv9:
          var1: linux
    ungrouped: {}
&nbsp;</pre></pre></div></div><br />
<br />
L'option --graph à la place de --list change le format de restitution :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
@all:
  |--@debian:
  |  |--srv1
  |  |--srv3
  |  |--srv4
  |  |--srv5
  |  |--srv6
  |--@ubuntu:
  |  |--srv10
  |  |--srv8
  |  |--srv9
  |--@ungrouped:
&nbsp;</pre></pre></div></div><br />
<br />
L'option --vars ajouté à l'option --graph ajoute les variables.<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
@all:
  |--@debian:
  |  |--srv1
  |  |  |--{var1 = debian}
  |  |--srv3
  |  |  |--{var1 = debian}
  |  |--srv4
  |  |  |--{var1 = debian}
  |  |--srv5
  |  |  |--{var1 = debian}
  |  |--srv6
  |  |  |--{var1 = debian}
  |  |--{var1 = debian}
  |--@ubuntu:
  |  |--srv10
  |  |  |--{var1 = linux}
  |  |--srv8
  |  |  |--{var1 = Ubuntu}
  |  |--srv9
  |  |  |--{var1 = linux}
  |  |--{var1 = linux}
  |--@ungrouped:
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-le-playbook">Le playbook</h2><br />

<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-creation-d-un-playbook">Création d'un playbook</h3><br />

<br />
Le playbook s'écrit au format yaml. Il peut se mettre à la racine du dossier ansible ou dans un sous-dossier.<br />
Il permet de faire le lien entre l'inventory et les tâches à réaliser.<br />
<br />
Pour y mettre directement des tasks, on peut l'écrire de cette façon :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
- name: "Mise à jour serveurs Debian"
  hosts: serveurs 
  become: yes
  become_method: su
  tasks:
    - name: "Update cache"
      apt:
        update_cache: yes
    - name: "Full-upgrade"
      apt:
        upgrade: full
    - name: "Autoremove & purge"
      apt:
        autoremove: yes
        purge: yes
    - name: "Vérification de la nécessité d'un reboot"
      register: reboot_required_file
      stat:
        path: /var/run/reboot-required
    - name: "Reboot si besoin"
      reboot:
        msg: "Reboot via Ansible"
        connect_timeout: 10
        reboot_timeout: 300
        test_command: uptime
      when:  reboot_required_file.stat.exists
&nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-utilisation-du-playbook">Utilisation du playbook</h3><br />

<br />
Pour lancer un playbook, on utilise la commande ansible-playbook.<br />
Par exemple :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ansible-playbook <span style="color: #660033;">-i</span> ..<span style="color: #000000; font-weight: bold;">/</span>00_inventory.yml <span style="color: #660033;">-K</span> <span style="color: #660033;">-C</span> upgrade.yml</pre></pre></div></div><br />
<br />
upgrade.yml est le chemin vers le playbook.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-quelques-modules">Quelques modules</h2><br />

<br />
Lorsqu'on lance un module (avec -m), on lui passe les paramètres avec l'option (-a puis entre " " les paramètres).<br />
Voir ci-dessous quelques exemples.<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-apt">apt</h3><br />

<br />
Le module apt permet de gérer les paquets. Les principaux paramètres sont :<br />
<ul class="formatter-ul">
    <li class="formatter-li">name : le nom du paquet
    </li><li class="formatter-li">state : le statut (present, absent, latest,...)<br />
</li></ul><br />
<br />
En CLI :<br />
<br />
<div class="formatter-container formatter-code code-BASH"><span class="formatter-title">Code BASH : </span><div class="formatter-content"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">ansible <span style="color: #660033;">-i</span> 00_inventory.yml transmission <span style="color: #660033;">-b</span> <span style="color: #660033;">-K</span> <span style="color: #660033;">--become-method</span>=<span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #660033;">-m</span> apt <span style="color: #660033;">-a</span> <span style="color: #ff0000;">"name=htop state=present"</span></pre></pre></div></div><br />
<br />
Via un playbook :<br />
<br />
<div class="formatter-container formatter-code code-TEXT"><span class="formatter-title">Code TEXT : </span><div class="formatter-content"><pre style="display:inline;"><pre class="text" style="font-family:monospace;">&nbsp;
- name: "Installation de htop"
  hosts: transmission  
  become: yes  
  become_method: su  
  tasks:
    - name: "Installation"
      apt:                     
        name: htop
        state: present
&nbsp;</pre></pre></div></div><br />
<br />
<br />]]></description>
                <pubDate>Sat, 19 Nov 2022 16:25:02 +0100</pubDate>
                
            </item>
		
	</channel>
</rss>
