Create SSH Keys on Ubuntu & Debian: 6 Easy Steps

1 Install OpenSSH

Ensure OpenSSH is installed on your system:

$ sudo apt update && sudo apt install openssh-client

2 Generate SSH Key Pair

Run this command to generate your SSH key pair:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • -t rsa: Specifies RSA algorithm
  • -b 4096: Sets 4096-bit key for better security
  • -C: Adds a comment (usually your email)

3 Secure with Passphrase

When prompted, enter a secure passphrase for additional protection.

4 Add to SSH-Agent

Add your new SSH key to the SSH-Agent:

$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa

5 Copy to Server

Copy your public key to the remote server:

$ ssh-copy-id user@remote_host

Or manually:

$ cat ~/.ssh/id_rsa.pub | ssh user@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

6 Verify Access

Test your SSH connection:

$ ssh user@remote_host
Secure Your Linux Servers with LinuxPatch.com

Visit LinuxPatch.com for automated patch management and security tools.