Last active
November 5, 2024 06:54
-
-
Save elonmallin/2cc94c45ab57e2060498e855acefade0 to your computer and use it in GitHub Desktop.
One-liner ssh-keygen and ssh-copy-id for Windows powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh-keygen && cat $env:userprofile/.ssh/id_rsa.pub | ssh user@linuxserver 'cat >> .ssh/authorized_keys' |
Don't know what you mean by the slashes since what is being piped to the ssh command is the content so slashes should have no impact.
usually windows have '\' and linux and unix have '/' so i was concerned. It seems, when used with $env:USERPROFILE
, either / or \ is fine.
i also followed chris's article on https://chrisjhart.com/Windows-10-ssh-copy-id/#copy-ssh-key-to-remote-linux-device
Thanks for the help
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
Thanks, I added the
:
to the env var. Don't know what you mean by the slashes since what is being piped to the ssh command is the content so slashes should have no impact. I'll keep the command shorter and ppl can feel free to add more specific params if they want =)