Skip to content

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

License

NANOmatic/ssh-copy-id

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”‘ Add SSH Key to Remote Server

PowerShell Platform SSH License Script

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)
    πŸ‘‰ Important: The key’s name must include the server identifier (e.g., ubuntu@10.74.90.100)

πŸš€ Usage in Windows (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.

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PowerShell 100.0%