Skip to content

Instantly share code, notes, and snippets.

@jhanley-com
Created December 15, 2021 21:30
Show Gist options
  • Save jhanley-com/643c8bff4eec2b5344d45bc85d30cc42 to your computer and use it in GitHub Desktop.
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/
powershell ./ssh-copy-id.ps1 %1 %2
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