Thursday, March 13, 2025

add ssh access to vm using public pem file

Ed25519 SSH Key Setup Guide

Adding an Ed25519 SSH Key for Remote Access

This guide walks you through generating an Ed25519 SSH key on Windows and adding it to a remote Ubuntu machine for SSH access.

Part 1: Generate the Ed25519 Key on Windows

  1. Open PowerShell (or Windows Terminal)
  2. Generate the SSH key :
    
    ssh-keygen -t ed25519 -C "your-email@example.com"
    
    
    
  3. When prompted for a file location , press Enter to accept the default location ( C:\Users\YourUsername.ssh\id_ed25519 ) or specify a custom path.
  4. When prompted for a passphrase , enter a secure passphrase or press Enter twice for no passphrase (less secure but more convenient).
  5. Verify your key was created :
    
    dir $env:USERPROFILE.ssh
    
    
    
    You should see the files id_ed25519 (private key) and id_ed25519.pub (public key).
  6. View your public key :
    
    Get-Content $env:USERPROFILE.ssh\id_ed25519.pub
    
    
    

Part 2: Add the Public Key to Your Ubuntu Server

Option 1: Using ssh-copy-id (if installed on Windows)

If you have ssh-copy-id available on your Windows machine:


ssh-copy-id -i $env:USERPROFILE.ssh\id_ed25519.pub username@ubuntu-server-ip


Option 2: Manual Method

  1. Copy your public key to clipboard :
    
    Get-Content $env:USERPROFILE.ssh\id_ed25519.pub | clip
    
    
    
  2. Connect to your Ubuntu server :
    
    ssh username@ubuntu-server-ip
    
    
    
  3. On the Ubuntu server, create/modify the authorized_keys file :
    
    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
    touch ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    
    
    
  4. Add your public key to authorized_keys :
    
    echo "PASTE_YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
    
    
    
    (Replace PASTE_YOUR_PUBLIC_KEY_HERE with your actual public key by right-clicking to paste)
  5. Exit the server :
    
    exit
    
    
    

Part 3: Test Your Connection


ssh username@ubuntu-server-ip


You should now connect without requiring a password (unless you set a passphrase on your SSH key).

Troubleshooting

  • If connection fails, check SSH service: sudo systemctl status ssh on Ubuntu
  • Verify file permissions: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys
  • Check SSH server config: /etc/ssh/sshd_config should have PubkeyAuthentication yes
  • Review SSH logs: sudo tail -f /var/log/auth.log on Ubuntu while attempting to connect

Ed25519 keys provide excellent security with shorter key lengths than RSA, making them both more secure and more convenient.

No comments:

Post a Comment