Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # ssh-copy-id for powershell.
  2. #
  3. function ssh-copy-id() {
  4. [CmdletBinding(DefaultParameterSetName='userAtMachine')]
  5. Param(
  6. [parameter(Mandatory=$false)]
  7. [String]
  8. $i,
  9.  
  10. [parameter(Mandatory=$true, ValueFromRemainingArguments=$true, ParameterSetName='userAtMachine')]
  11. [String]
  12. $userAtMachine
  13. )
  14. if (!$i) {
  15. $publicKey = "$ENV:USERPROFILE" + "/.ssh/id_ed25519.pub"
  16. } else {
  17. $publicKey = $i
  18. }
  19. Write-Host $publicKey
  20. if (!(Test-Path "$publicKey")){
  21. Write-Error "ERROR: failed to open ID file '$publicKey': No such file"
  22. }
  23. else {
  24. & cat "$publicKey" | ssh $userAtMachine "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement