mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-05 12:37:08 +02:00
Added new-ssh-key.ps1
This commit is contained in:
parent
dc2f4fdfd1
commit
45bd64688e
31
scripts/new-ssh-key.ps1
Normal file
31
scripts/new-ssh-key.ps1
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Creates a new SSH key
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script creates a new SSH key for the user.
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./new-ssh-key.ps1
|
||||||
|
✔️ Your public key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILb8s5zU9YDApGQ82H45fMKVPMr5cw9fzh3PEBjZZ+Rm markus@PI
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
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"
|
||||||
|
} elseif (Test-Path "~/.ssh/id_rsa.pub") {
|
||||||
|
$publicKey = Get-Content "~/.ssh/id_rsa.pub"
|
||||||
|
} else {
|
||||||
|
throw "No public key found."
|
||||||
|
}
|
||||||
|
"✔️ Your public key: $publicKey"
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user