SSH keys provide a secure way to log in to your Linux server without using a password.
Generate SSH Key Pair
- Open terminal
- Run this command:
ssh-keygen -t ed25519 -C "your_email@example.com"
- Press Enter to save the key in the default location
- Enter a passphrase (recommended) or leave empty
Copy Public Key to Server
Use either method:
Method 1: ssh-copy-id
ssh-copy-id username@server_ip
Method 2: Manual copy
- View your public key:
cat ~/.ssh/id_ed25519.pub
- Connect to your server:
ssh username@server_ip
- Create SSH directory:
mkdir -p ~/.ssh chmod 700 ~/.ssh
- Add your key:
echo "public_key_string" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
Test Connection
ssh username@server_ip
You should connect without needing a password.