Ssh.ps1
function Initialize-Ssh { if (-Not(Get-Command "ssh" -ErrorAction SilentlyContinue)) { Install-Scoop scoop install ssh } } enum SshAlgo { rsa ed25519 } function Get-SshKey { param( [SshAlgo] $Type = [SshAlgo]::ed25519, [switch] $Public ) Initialize-Ssh if (-not(Test-Path -Path $HOME/.ssh -PathType Container)) { New-Item -Path $HOME/.ssh -ItemType Directory | Out-Null } if ($Type -Eq [SshAlgo]::ed25519) { $key = "id_ed25519_box" } else { $key = "id_rsa_box" } $key_path = "$global:HOME/.ssh/${key}" if (-not(Test-Path -Path $key_path -PathType Leaf)) { Write-Host("Creando clave ssh '${key_path}'") # No podem crear una clau sense contrasenya sense preguntar a l'usuari fent servir la opció -N '' perquè a vegades ha de ser '""', però a vegades ha de ser 'xxxxx' mínim 5 caracters i no admet '""'. if ($Type -Eq [SshAlgo]::ed25519) { ssh-keygen -t ed25519 -f ${key_path} } else { ssh-keygen -m PEM -t rsa -b 4096 -f $HOME\.ssh\id_rsa } } if ($Public) { $key_path = "$global:HOME/.ssh/${key}.pub" } return $key_path } Export-ModuleMember -Function 'Get-SshKey' |