Skip to content

Instantly share code, notes, and snippets.

@alexjsteffen
Created February 27, 2025 01:58
Show Gist options
  • Save alexjsteffen/2cfd1ada1e150634cae4f2dc2cc1a604 to your computer and use it in GitHub Desktop.
Save alexjsteffen/2cfd1ada1e150634cae4f2dc2cc1a604 to your computer and use it in GitHub Desktop.

Adding SSH Public Keys to a Remote Server

To add your SSH public keys to the authorized_keys file on a remote Linux server, follow these steps:

Prerequisites

  • Ensure OpenSSH is installed on your Windows machine.
  • Locate your SSH public key files.

Commands

For id_ed25519.pub

type C:\Users\ajhs\.ssh\id_ed25519.pub | ssh username@remote_server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

For id_ecdsa.pub

type C:\Users\ajhs\.ssh\id_ecdsa.pub | ssh username@remote_server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

For id_dsa.pub

type C:\Users\ajhs\.ssh\id_dsa.pub | ssh username@remote_server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Explanation

  • Each command reads the content of the respective public key file using type.
  • The output is piped (|) to the ssh command, which connects to the remote server.
  • The remote command mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys ensures the .ssh directory exists and appends the public key to the authorized_keys file.

Note: Replace username with your remote server username and remote_server with the IP address or hostname of your remote server.


This Markdown text box provides a clear and structured way to present the commands and their explanations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment