Skip to content

new-ssh-key

Create a new SSH key

#Requires -Version 5.1

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
} catch {
throw
}

This script has no configurable parameters.

An interactive directory of PowerShell scripts.