Create New Key Pair for SSH
Create the Key Pair
-C "": No comment on the public key string-f "~/my_ssh_key": Output in the current user's home folder and use the base name asmy_ssy_key
my_ssh_key: private key file- Never share this
my_ssh_key.pub: public key file- Add this to
authorized_keysfor target user on any target host(s)
- Add this to
-N "": No passphrase when generating key
Bash
ssh-keygen -t ed25519 -C "" -f "~/my_ssh_key" -N ""
PowerShell
ssh-keygen -t ed25519 -C '""' -f "my_ssh_key" -N '""'
Configure SSH Host(s)
Obtain Public Key String
cat ~/my_ssh_key.pub
Copy the output
Add as Authorized Key
echo 'ssh-ed25519 AAAAC3...[SNIP]...pNvcP' >> ~/.ssh/authorized_ekys
Append the public key string to the target user's authorized_keys file
Authenticate with Private Key
# FQDN
ssh -i my_ssh_key username@hostname.domain.tld
# IP
ssh -i my_ssh_key username@192.168.10.125
Recall that before we added my_ssh_key.pub contents to ~/.ssh/authorized_keys. The example above assumes something like /home/username/.ssh/authorized_keys or C:\Users\username\.ssh\authorized_keys.
Therefore when we authenticate with the private key, we indicate username @ host, where host is the computer where you modified /home/username/.ssh/authorized_keys.