Skip to content

Instantly share code, notes, and snippets.

@blowdart
Last active February 23, 2022 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blowdart/4a354acae8f415ac93362ed5d95d2236 to your computer and use it in GitHub Desktop.
Save blowdart/4a354acae8f415ac93362ed5d95d2236 to your computer and use it in GitHub Desktop.
Importing github commit signing keys via powershell
<#
.SYNOPSIS
Imports github pgp signing keys for one or more users.
.DESCRIPTION
Imports github commit signing keys for one or more github usernames into your gpg key ring.
You still need to assign trust levels to keys after their import, see https://www.gnupg.org/gph/en/manual/x334.html
.PARAMETER Users
A comma seperated list of github usernames whose keys will be retrieved amd imported.
.EXAMPLE
.\ImportGithubSigningKeys blowdart
.LINK
https://help.github.com/articles/signing-commits-using-gpg/
https://www.gnupg.org/gph/en/manual/x334.html
#>
[CmdletBinding(DefaultParameterSetName="Users")]
param(
[Parameter(Mandatory=$true, Position=0, ParameterSetName="Users",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Users whose keys to import...")]
[ValidateNotNullOrEmpty()]
[string[]]
$githubUsers
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$importFileName = "importedGitHubKeys.asc"
$githubUsers |% {Invoke-WebRequest https://api.github.com/users/$_/gpg_keys | ConvertFrom-Json } |% {$_.raw_key} | Out-File -Append -Encoding ascii $importFileName
gpg --import $importFileName
Remove-Item $importFilename 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment