Skip to content

New-SshKey

Create a new SSH key

try {
	& ssh-keygen
	if ($lastExitCode -ne 0) { throw "ssh-keygen failed" }

	if (Test-Path "~/.ssh/id_ed25519.pub") {
		$publicKey = Get-Content "~/.ssh/id_ed25519.pub"
		$type = "Ed25519"
	} elseif (Test-Path "~/.ssh/id_rsa.pub") {
		$publicKey = Get-Content "~/.ssh/id_rsa.pub"
		$type = "RSA"
	} else {
		throw "No public key found."
	}
	"? Your new SSH key has been saved to ~/.ssh ($type type). The public key is:"
	"   $publicKey"
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

This script has no configurable parameters.

An interactive directory of PowerShell scripts.