Windows + PowerShell quick SSH key add to VPS
For Windows + PowerShell when you already have an SSH key and just want to add it to your VPS fast.
Method A — One-liner push from Windows (fastest)
Prereq: You can still log in to the VPS with a password.
Replace user@YOUR_VPS_IP with your actual user and IP/domain. If you use root, use root@IP. If your public key file isn’t the default, change id_ed25519.pub to your actual .pub path.
# Default public key path: C:\Users\<you>\.ssh\id_ed25519.pub
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@YOUR_VPS_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Non-default SSH port (example 2222):
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh -p 2222 user@YOUR_VPS_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Test login:
ssh user@YOUR_VPS_IP
# If you’re not using the default private key filename, specify it:
# ssh -i $env:USERPROFILE\.ssh\id_ed25519 user@YOUR_VPS_IP
Method B — Append key while you’re already on the VPS
If you’re already in a shell on the VPS (via password or provider console), run on the VPS:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-ed25519 AAAA... your_email_or_comment" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Get your key content on Windows to paste:
type $env:USERPROFILE\.ssh\id_ed25519.pub
Optional: make connections easier (SSH config on Windows)
Create or edit:
notepad $env:USERPROFILE\.ssh\config
Add:
Host my-vps
HostName <your-ip-address>
User root
IdentityFile ~/.ssh/id_ed25519
# Port 22
Then connect with:
ssh my-vps
Quick fixes & gotchas
- Permissions on VPS must be exact:
~/.ssh→700,~/.ssh/authorized_keys→600. - SELinux (RHEL/CentOS/Fedora):
restorecon -Rv ~/.ssh - Password login disabled?
Use the cloud provider console (VNC/rescue), then use Method B to paste your public key. - Multiple users: Put the key in the user’s home you’ll SSH into (e.g.,
/root/.ssh/authorized_keysforroot).
If you share your actual user, IP/port, and key filename, I can give you a single copy-paste command tailored to your box.