tech:generer_un_mot_de_passe
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:generer_un_mot_de_passe [2025/05/25 18:55] – Jean-Baptiste | tech:generer_un_mot_de_passe [2026/07/16 15:13] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Générer un mot de passe | ||
| + | |||
| + | Un bon mot de passe contient : majuscule, minuscule, trait d' | ||
| + | |||
| + | Keepassx / Keepass propose un générateur de mot de passe. | ||
| + | |||
| + | Générer un mot de passe vous-même : [Gérer ses mots de passe](https:// | ||
| + | |||
| + | Sinon : | ||
| + | ~~~bash | ||
| + | dd if=/ | ||
| + | ~~~ | ||
| + | |||
| + | ou | ||
| + | |||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | Pour un code décimal | ||
| + | ~~~bash | ||
| + | echo $RANDOM$RANDOM | ||
| + | ~~~ | ||
| + | |||
| + | Aléatoirement A ou B | ||
| + | ~~~bash | ||
| + | r=(A B) | ||
| + | echo ${r[RANDOM%2]} | ||
| + | ~~~ | ||
| + | |||
| + | Avec pwgen | ||
| + | |||
| + | ~~~bash | ||
| + | pwgen -Bs1 16 | ||
| + | pwgen -y1 16 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Avec OpenSSL | ||
| + | ~~~bash | ||
| + | openssl rand -hex 10 | ||
| + | openssl rand -base64 16 | sed -e " | ||
| + | openssl rand 300 | perl -pe ' | ||
| + | ~~~ | ||
| + | |||
| + | Avec apg | ||
| + | ~~~bash | ||
| + | apg -q -a 0 -n 1 -m 12 -M NCL | ||
| + | apg -a 1 -m 32 -n 1 -M NCL | ||
| + | ~~~ | ||
| + | |||
| + | Avec GPG | ||
| + | ~~~bash | ||
| + | gpg --gen-random --armor 0 24 | ||
| + | ~~~ | ||
| + | |||
| + | Avec Ansible \ | ||
| + | `community.general.random` | ||
| + | |||
| + | |||
| + | ## Générer une emprunte (hash) de mdp | ||
| + | |||
| + | Hash md5 | ||
| + | ~~~bash | ||
| + | mkpasswd --hash=md5 $PASS | ||
| + | ~~~ | ||
| + | |||
| + | Hash SHA-512 (`$6$` defaut GNU/Linux / | ||
| + | ~~~bash | ||
| + | mkpasswd --method=sha-512 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | openssl passwd -6 -salt MySaltPlop | ||
| + | openssl passwd -6 <(echo ' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ man crypt | ||
| + | ID | Method | ||
| + | ───────────────────────────────────────────────────────── | ||
| + | 1 | MD5 | ||
| + | 2a | Blowfish (not in mainline glibc; added in some | ||
| + | | Linux distributions) | ||
| + | 5 | SHA-256 (since glibc 2.7) | ||
| + | 6 | SHA-512 (since glibc 2.7) | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | pass=" | ||
| + | salt=" | ||
| + | useradd \ | ||
| + | --shell /bin/bash \ | ||
| + | --create-home \ | ||
| + | --groups sudo \ | ||
| + | --password " | ||
| + | user1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | ## Entropie / | ||
| + | |||
| + | |||
| + | The Linux kernel facilitates random number generation through two devices: /dev/random and / | ||
| + | |||
| + | * `/ | ||
| + | * `/ | ||
| + | |||
| + | The kernel maintains an entropy pool for these devices. The entropy pool is fed by entropy sources of the system, typically coming from the keyboard, the mouse, and some other device drivers or IRQs. Entropy from the entropy pool is consumed in the generation of random data (i.e. through reads from /dev/random and / | ||
| + | |||
| + | |||
| + | Voir : | ||
| + | * [BoottimeEntropyStarvation](https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Voir aussi : haveged, rng-tools, rngd, crng | ||
| + | |||
| + | rng-tools | ||
| + | The rng-tools and haveged supports the " | ||
| + | |||
| + | Voir one-rng | ||
| + | * [one-rng](https:// | ||
| + | * https:// | ||
| + | |||
| + | Hardware : | ||
| + | * OneRNG | ||
| + | * FST-01 (Flying Stone Tiny ZERO-ONE) | ||
| + | * Infinite Noise TRNG | ||
| + | |||
| + | Check the available entropy | ||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### rngd - rng-tools | ||
| + | |||
| + | Sur RedHat | ||
| + | ~~~bash | ||
| + | yum install rng-tools | ||
| + | systemctl enable --now rngd | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # systemctl status rngd | ||
| + | ● rngd.service - Hardware RNG Entropy Gatherer Daemon | ||
| + | | ||
| + | | ||
| + | Main PID: 1170 (rngd) | ||
| + | Tasks: 2 (limit: 48756) | ||
| + | | ||
| + | | ||
| + | | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Non-preferred method: seed randomness source from non-blocking source | ||
| + | |||
| + | source : https:// | ||
| + | |||
| + | NOTE: This method is potentially insecure. This method should only be used when no other source of entropy can be supplied, and software cannot be changed to use an alternative source besides /dev/random | ||
| + | |||
| + | |||
| + | You can see the entropy value using the following command: | ||
| + | Raw | ||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | Now, start the rngd daemon using following command and monitor the entropy on the system: | ||
| + | Raw | ||
| + | ~~~bash | ||
| + | rngd -r / | ||
| + | watch -n 1 cat / | ||
| + | ~~~ | ||
| + | |||
| + | NOTE: Seeding /dev/random with data derived from / | ||
| + | |||
| + | ### Autres | ||
| + | |||
| + | Voir | ||
| + | * /dev/hwrng | ||
| + | * / | ||
| + | * / | ||
| + | * / | ||
| + | |||
| + | |||
| + | If you run the following, you will may see that available entropy is very low (< 128) and thus reading from /dev/random is likely to block. | ||
| + | Raw | ||
| + | ~~~bash | ||
| + | while sleep 1; do cat / | ||
| + | ~~~ | ||
| + | You can set this temporarily to 1024 (default is 64) | ||
| + | Raw | ||
| + | ~~~bash | ||
| + | echo 1024 > / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Test | ||
| + | |||
| + | An entropy source can be tested for (FIPS-compliant) randomness using the rng-tools or rng-utils. | ||
| + | |||
| + | ~~~bash | ||
| + | rngtest -c 1000 </ | ||
| + | ~~~ | ||
| + | Voir https:// | ||
| + | |||
| + | |||
| + | ### TRNG | ||
| + | |||
| + | scdrand | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ### Pb boot | ||
| + | |||
| + | ~~~ | ||
| + | [ 1.616819] random: fast init done | ||
| + | [ 2.299314] random: crng init done | ||
| + | ~~~ | ||
| + | |||
| + | Kernel boot parameter | ||
| + | ~~~ini | ||
| + | random.trust_cpu=on | ||
| + | ~~~ | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | ## Infinite Noise TRNG | ||
| + | |||
| + | Voir : | ||
| + | * http:// | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install infnoise | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # #infnoise --raw --debug > / | ||
| + | # infnoise --debug --no-output | ||
| + | Generated 1048576 bits. OK to use data. Estimated entropy per bit: 0.875409, estimated K: 1.834528 | ||
| + | num1s: | ||
| + | Generated 2097152 bits. OK to use data. Estimated entropy per bit: 0.871953, estimated K: 1.830139 | ||
| + | num1s: | ||
| + | Generated 3145728 bits. OK to use data. Estimated entropy per bit: 0.872259, estimated K: 1.830528 | ||
| + | num1s: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | # systemctl status infnoise | ||
| + | ● infnoise.service - Wayward Geek InfNoise TRNG driver | ||
| + | | ||
| + | | ||
| + | Docs: man: | ||
| + | Process: 43156 ExecStart=/ | ||
| + | Main PID: 43157 (infnoise) | ||
| + | Tasks: 1 (limit: 8733) | ||
| + | | ||
| + | CPU: 69ms | ||
| + | | ||
| + | | ||
| + | |||
| + | Jul 24 20:23:18 vivobela systemd[1]: Starting infnoise.service - Wayward Geek InfNoise TRNG driver... | ||
| + | Jul 24 20:23:18 vivobela systemd[1]: Started infnoise.service - Wayward Geek InfNoise TRNG driver. | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | systemctl status dev-infnoise.device | ||
| + | ~~~ | ||
| + | |||
