SSH connection with public key
Published on 2 min read
Updated on
Seriesgnu-linux-infrastructure
Part 6 of 6In this series22 min read in total
Connect with a public key rather than a User/Password represents several advantages:
- a generated key will always be more robust than a password in general
- there is no need to use a password to connect to SSH
Generation of the key
- Choose the key type according to the server capabilities. Ed25519 is recommended on modern systems, while RSA 4096 remains useful for compatibility with older servers.
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 SADS 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@MondomainThe Key's Randomart Image is:+-[Ed25519 256]-+|%@+.|| EBCVB.||+= BO.||+.O*.|| oo..o.S S || =+oo o || B ++ o..||+= .. o.|| o...|+---- [SHA256] -----+Inform connection information
ssh-copy-id contact@mydomainssh-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-Iid: info: attempting to log in with the new key (s), to filter out any that are alreni installedy/usr/bin/ssh-copy-ID: info: 1 key (s) remain to be installed-if you are prompt now it is to install the 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.Connect to SSH
ssh admin@dns.it.frssh nom_user@ip_ou_domaine