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.
- Host: GitHub
- URL: https://github.com/sewertronics/ssh-copy-id
- Owner: Sewertronics
- License: mit
- Created: 2025-09-12T13:55:04.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2025-09-25T13:32:31.000Z (4 months ago)
- Last Synced: 2025-09-25T15:33:16.080Z (4 months ago)
- Topics: automation, cross-platform, devops, linux, powershell, script, server-management, ssh, ssh-agent, windows, wsl
- Language: PowerShell
- Homepage: http://www.sewertronics.com
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔑 Add SSH Key to Remote Server
[](https://docs.microsoft.com/powershell/)
[](https://www.microsoft.com/windows/)
[](https://www.openssh.com/)
[](LICENSE)
[](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
© 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.