Skip to main content

SSH Key Authentication Create and Share

Why SSH Keys are Important? SSH keys use asymmetric encryption—a public key is placed on the server, and a private key stays on your device.

Benefits over Passwords 

  • Security: Keys are far more resistant to brute-force attacks than passwords
  • Convenience: No need to type passwords every time
  • Automation: Ideal for scripts and remote tasks
  • Granular Access: You can assign different keys to different users or devices

Pre requisite- Needs OpenSSH if not already installed.

Generating SSH Keys

  1. On your local computer that will be used to establish connection with a server
  2. In terminal type following command
ssh-keygen -t rsa -b 4096 -C "key name"

"-t rsa" - specifies the type of key RSA

"b 4096" - Sets the key length to 4096 bits

"-C" - Adds a comment, optional

or use ed25519 for stronger encryption

ssh-keygen -t rsa -t ed25519 -C "key name"

  1. Copy Public Key to Server
ssh-copy-id username@server_ip

Or if you make multiple different keys

ssh-copy-id ~/.ssh/id_rsa_work.pub 'name of the key you want to copy' username@server_ip 

More Info on managing multiple keys check Managing Multiple SSH Keys