An open API service indexing awesome lists of open source software.

https://github.com/sewertronics/ssh-copy-id

🔑 PowerShell script to safely add SSH public keys from your local ssh-agent to remote servers, preserving comments and appending your Windows username.
https://github.com/sewertronics/ssh-copy-id

automation cross-platform devops linux powershell script server-management ssh ssh-agent windows wsl

Last synced: 4 months ago
JSON representation

🔑 PowerShell script to safely add SSH public keys from your local ssh-agent to remote servers, preserving comments and appending your Windows username.

Awesome Lists containing this project

README

          

# 🔑 Add SSH Key to Remote Server

[![PowerShell](https://img.shields.io/badge/language-PowerShell-blue?logo=powershell)](https://docs.microsoft.com/powershell/)
[![Platform](https://img.shields.io/badge/platform-Windows-lightgrey?logo=windows)](https://www.microsoft.com/windows/)
[![SSH](https://img.shields.io/badge/SSH-Enabled-green?logo=ssh)](https://www.openssh.com/)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
[![Script](https://img.shields.io/badge/type-script-yellow)](add-sshkey.ps1)

This PowerShell script adds an SSH public key from your local `ssh-agent` to a remote server's `authorized_keys` file. It preserves the key’s original comment and appends your Windows username for identification. The script ensures the `.ssh` directory and `authorized_keys` file exist, sets correct permissions, and can optionally use password authentication.

## 🌟 Features

- ✅ Appends public key **only once** to avoid duplicates
- 📝 Preserves original key comment and appends your Windows username
- 🛠 Works even if `.ssh` or `authorized_keys` does not exist
- 🔐 Can force **password authentication** to avoid `Too many authentication failures`
- ⚡ Simple usage on Windows PowerShell
- 🧩 Safe with multiple keys in your SSH agent
- 📌 Keeps permissions secure for `.ssh` and `authorized_keys`

## 📋 Requirements

- 🖥 Windows PowerShell (5.1+) or PowerShell 7+
- 🔧 SSH installed (`ssh` command available)
- 🗝 Optional: SSH agent running with keys loaded (e.g., via Bitwarden)
- 🌐 Remote server accessible over SSH
- 🔑 Ensure your SSH key is added to the **Bitwarden SSH agent** (it has to be enabled - [Settings -> Enable SSH agent](https://bitwarden.com/help/ssh-agent/#enable-ssh-agent))

👉 **Important**: The key’s name must include the server identifier (e.g., `ubuntu@10.74.90.100`)

## 🚀 Usage in Windows (PowerShell)

```powershell
# Basic usage
git clone git@github.com:Sewertronics/ssh-copy-id.git
cd ssh-copy-id
.\ssh-copy-id.ps1 ubuntu@10.74.90.100
```

## ©️ Copyright

Docker Logo
© 2025 Sewertronics Sp z o.o.

This project is licensed under the [MIT License](LICENSE).

All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted under the terms of the MIT License.