Skip to content

Instantly share code, notes, and snippets.

@elonmallin
Last active November 5, 2024 06:54
Show Gist options
  • Save elonmallin/2cc94c45ab57e2060498e855acefade0 to your computer and use it in GitHub Desktop.
Save elonmallin/2cc94c45ab57e2060498e855acefade0 to your computer and use it in GitHub Desktop.
One-liner ssh-keygen and ssh-copy-id for Windows powershell
ssh-keygen && cat $env:userprofile/.ssh/id_rsa.pub | ssh user@linuxserver 'cat >> .ssh/authorized_keys'
@fquinner
Copy link

Since google took me here when searching for a powershell ssh-copy-id, I thought I'd share my modifications to the above which allows for configurable host and uses default ssh pub key as well as ensuring permissions are correct (I just stick this in my profile script):

function ssh-copy-id($server) {
    type $env:USERPROFILE\.ssh\id_rsa.pub | ssh $server "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
}

Thank you very much for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment