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.
- β Appends public key only once to avoid duplicates
- π Preserves original key comment and appends your Windows username
- π Works even if
.sshorauthorized_keysdoes 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
.sshandauthorized_keys
- π₯ Windows PowerShell (5.1+) or PowerShell 7+
- π§ SSH installed (
sshcommand 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)
π Important: The keyβs name must include the server identifier (e.g.,ubuntu@10.74.90.100)
# Basic usage
git clone git@github.com:Sewertronics/ssh-copy-id.git
cd ssh-copy-id
.\ssh-copy-id.ps1 ubuntu@10.74.90.100This project is licensed under the MIT 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.
