Created
December 15, 2021 21:30
-
-
Save jhanley-com/643c8bff4eec2b5344d45bc85d30cc42 to your computer and use it in GitHub Desktop.
PowerShell script to copy SSH public key to a Linux system. This is for my article on OpenSSH - https://www.jhanley.com/ubuntu-20-04-desktop-installing-and-configuring-ssh/
This file contains hidden or 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
powershell ./ssh-copy-id.ps1 %1 %2 |
This file contains hidden or 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
if ($args.count -lt 1) | |
{ | |
Write-Host "Error: Missing filename" | |
Write-Host "Usage: ssh-copy-id.ps1 <public-key-filename> <username@host>" | |
Exit | |
} | |
if ($args.count -lt 2) | |
{ | |
Write-Host "Error: Missing username@host string" | |
Write-Host "Usage: ssh-copy-id.ps1 <public-key-filename> <username@host>" | |
Exit | |
} | |
$key = $args[0] | |
$sshhost = $args[1] | |
if (-not(Test-Path $key -PathType Leaf)) { | |
Write-Host "Error: file does not exist" | |
Write-Host "File: $key" | |
Exit | |
} | |
Write-Host "Installing SSH publilc key: $key to host $sshhost" | |
type $key | ssh $sshhost "if [ ! -d .ssh ]; then mkdir .ssh; fi && cat >> ~/.ssh/authorized_keys" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment