Connexion SSH avec clé publique
Publié le 2 min de lecture
Mis à jour le
Partie 6 sur 6
Dans cette série22 min de lecture au total
Se connecter avec une clé publique plutôt qu’avec un User/Password représente plusieurs avantages :
- une clé générée sera toujours plus robuste qu’un mot de passe en général
- il n’y a pas besoin d’utiliser de mot de passe pour se connecter en SSH
Génération de la clé
- Choisissez le type de clé selon les capacités du serveur. Ed25519 est le choix recommandé pour un système moderne, tandis que RSA 4096 reste utile pour la compatibilité avec des serveurs plus anciens.
ssh-keygen -t ed25519ssh-keygen -t rsa -b 4096Generating public/private ed25519 key pair.Enter file in which to save the key (/home/contact/.ssh/id_ed25519):Created directory '/home/contact/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/contact/.ssh/id_ed25519Your public key has been saved in /home/contact/.ssh/id_ed25519.pubThe key fingerprint is:SHA256:monhash contact@mondomaineThe key's randomart image is:+--[ED25519 256]--+|%@+. ||EBCVB. ||+=Bo. ||+.o* . ||oo..o . S S ||=+oo o ||B++ o . . ||+=.. o . ||o. . . |+----[SHA256]-----+Renseigner les informations de connexion
ssh-copy-id contact@mondomainessh-copy-id nom_user@ip_ou_domaine
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"The authenticity of host 'dns.it.fr (172.16.10.10)' can't be established.ECDSA key fingerprint is SHA256:lda9Psn+r3CoE3P2eH2hDAR6f50GaTNlUTF5Hw+QqKA.Are you sure you want to continue connecting (yes/no/[fingerprint])? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysadmin@dns.it.fr's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'admin@dns.it.fr'"and check to make sure that only the key(s) you wanted were added.Se connecter en SSH
ssh admin@dns.it.frssh nom_user@ip_ou_domaine