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 | ||
| pratique:informatique:bastionssh [07/05/2025 18:02] – Zatalyz | pratique:informatique:bastionssh [09/05/2025 17:14] (Version actuelle) – [Configuration côté utilisatrice] Zatalyz | ||
|---|---|---|---|
| Ligne 63: | Ligne 63: | ||
| Concernant le port ssh, dans le cas que je traite, Bastion2 est derrière une box. Cette dernière n' | Concernant le port ssh, dans le cas que je traite, Bastion2 est derrière une box. Cette dernière n' | ||
| - | <code bash sshd_config/ | + | <code bash /etc/ssh/sshd_config.d/ |
| # Protocole et sécurité de base | # Protocole et sécurité de base | ||
| Protocol 2 | Protocol 2 | ||
| Ligne 78: | Ligne 78: | ||
| # Authentification | # Authentification | ||
| PermitRootLogin no | PermitRootLogin no | ||
| - | AllowGroups wheel,jump | + | AllowGroups wheel jump |
| PasswordAuthentication no | PasswordAuthentication no | ||
| Ligne 109: | Ligne 109: | ||
| LogLevel VERBOSE | LogLevel VERBOSE | ||
| - | # Match optionnel pour restreindre plus finement (exemple) | + | # Match précise qui a droit à quoi |
| Match Group jump | Match Group jump | ||
| + | # AllowTcpForwarding nécessaire pour que ce soit transmis, | ||
| + | # Renseigner ensuite les adresses et ports. | ||
| + | | ||
| | | ||
| | | ||
| | | ||
| - | Match User alice | + | Match Group wheel |
| - | | + | |
| - | + | ||
| - | Match User lapin | + | |
| PermitTTY yes | PermitTTY yes | ||
| ForceCommand none | ForceCommand none | ||
| Ligne 161: | Ligne 161: | ||
| </ | </ | ||
| + | === Créer les utilisatrices === | ||
| + | Il faut permettre à Alice de passer en rebondissant et sans s' | ||
| + | |||
| + | Tout en root/sudo : | ||
| + | < | ||
| + | groupadd wheel | ||
| + | groupadd jump | ||
| + | useradd alice -m -G jump | ||
| + | mkdir / | ||
| + | nano / | ||
| + | # Mettre la clé publique dans ce fichier | ||
| + | chown -R alice: / | ||
| + | chmod 0700 / | ||
| + | chmod 0600 / | ||
| + | |||
| + | useradd lapin -m -G sudo, | ||
| + | passwd lapin | ||
| + | mkdir / | ||
| + | nano / | ||
| + | # Mettre la clé publique dans ce fichier | ||
| + | chown -R lapin: / | ||
| + | chmod 0700 / | ||
| + | chmod 0600 / | ||
| + | |||
| + | === L' | ||
| + | Bastion2 étant l' | ||
| + | < | ||
| + | ping 192.168.1.10 | ||
| + | ip neigh</ | ||
| + | |||
| + | Si ça ne trace pas la route, si ça ne ping pas... la dernière commande liste les ip voisines, ça peut donner des pistes. | ||
| ==== Configuration côté Serveur final ==== | ==== Configuration côté Serveur final ==== | ||
| * sshd_config | * sshd_config | ||
| * Accepter uniquement des connexions depuis Bastion2 | * Accepter uniquement des connexions depuis Bastion2 | ||
| - | |||
| <code bash sshd_config/ | <code bash sshd_config/ | ||
| + | # Protocole et sécurité de base | ||
| Protocol 2 | Protocol 2 | ||
| - | Ciphers aes256-ctr, | + | StrictModes yes |
| - | MACs hmac-sha2-512-etm@openssh.com, | + | |
| + | # Chiffrement et algorithmes | ||
| + | HostKey / | ||
| + | KexAlgorithms sntrup761x25519-sha512, | ||
| + | Ciphers chacha20-poly1305@openssh.com, | ||
| + | MACs hmac-sha2-256-etm@openssh.com, | ||
| + | PubkeyAcceptedAlgorithms ssh-ed25519, | ||
| + | |||
| + | # Authentification | ||
| PermitRootLogin no | PermitRootLogin no | ||
| - | StrictModes yes | + | AllowGroups wheel |
| PasswordAuthentication no | PasswordAuthentication no | ||
| + | PermitEmptyPasswords no | ||
| KbdInteractiveAuthentication no | KbdInteractiveAuthentication no | ||
| PubkeyAuthentication yes | PubkeyAuthentication yes | ||
| UsePAM yes | UsePAM yes | ||
| - | PermitEmptyPasswords no | + | # Paramètres de session et de connexion |
| MaxAuthTries 6 | MaxAuthTries 6 | ||
| LoginGraceTime 30 | LoginGraceTime 30 | ||
| + | ClientAliveInterval 3m | ||
| + | ClientAliveCountMax 5 | ||
| - | AllowGroups wheel | + | # Comportement à la connexion, environnement |
| - | + | ||
| - | AllowTcpForwarding no | + | |
| - | X11Forwarding no | + | |
| - | + | ||
| PrintLastLog yes | PrintLastLog yes | ||
| PrintMotd no | PrintMotd no | ||
| - | + | PermitUserEnvironment no | |
| AcceptEnv LANG LC_* | AcceptEnv LANG LC_* | ||
| - | + | ||
| - | Subsystem sftp / | + | # Redirections et accès à distance |
| + | AllowTcpForwarding no | ||
| + | X11Forwarding no | ||
| </ | </ | ||
| + | |||
| === Cas particulier d'un tunnel === | === Cas particulier d'un tunnel === | ||
| Dans un cas particulier, | Dans un cas particulier, | ||
| Ligne 241: | Ligne 280: | ||
| Génération de sa clé : | Génération de sa clé : | ||
| < | < | ||
| - | <WRAP center round todo 60%> | ||
| - | Copier la clé sur la/les VM auxquelles elle a accès ainsi que dans les deux bastions, dans ''/ | + | Copier la clé **publique** |
| - | Son fichier de config | + | Son fichier de config |
| + | <code bash ~/ | ||
| + | # Bastion2 | ||
| + | Host bastion2 | ||
| + | HostName 192.168.1.22 | ||
| + | User alice | ||
| + | IdentityFile ~/ | ||
| + | ForwardAgent no | ||
| + | |||
| + | # Accès à la VM finale (via les deux bastions) | ||
| + | Host vm-finale | ||
| + | HostName 192.168.1.11 | ||
| + | User alice | ||
| + | IdentityFile ~/ | ||
| + | ProxyJump bastion2 | ||
| + | </ | ||
| + | |||
| + | <WRAP center round todo 60%> | ||
| <code bash ~/ | <code bash ~/ | ||
| # Bastion1 - 1er saut | # Bastion1 - 1er saut | ||
| Ligne 275: | Ligne 330: | ||
| Pour se connecter : | Pour se connecter : | ||
| ssh vm-finale | ssh vm-finale | ||
| + | |||
| + | <WRAP center round tip 100%> | ||
| + | Attention si on utilise un script (genre [[pratique: | ||
| + | </ | ||
| + | |||
| + | |||
| {{tag> | {{tag> | ||