-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpg_key_gen.sh
executable file
·29 lines (24 loc) · 1.2 KB
/
gpg_key_gen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Check for existing GPG keys
existing_keys=$(gpg --list-secret-keys --keyid-format LONG)
if [[ -z "$existing_keys" ]]; then
# Generate GPG key
gpg --full-generate-key
# List the GPG keys for which you have both a public and private key
gpg --list-secret-keys --keyid-format LONG
KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print substr($0,15,16)}' | head -1)
# To get the GPG key ID
echo "Copying GPG Key to clipboard"
gpg --armor --export $KEY_ID | pbcopy
echo "Click here and paste the key in the appropriate text field: https://github.com/settings/gpg/new"
echo "After that run: git config --global user.signingkey ${KEY_ID}"
git config commit.gpgsign true
else
echo "GPG key(s) already exists."
gpg --list-secret-keys --keyid-format LONG
KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print substr($0,15,16)}' | head -1)
echo "Next run: gpg --armor --export ${KEY_ID} | pbcopy"
echo "Click here and paste the key in the appropriate text field: https://github.com/settings/gpg/new"
echo "After that run: git config --global user.signingkey ${KEY_ID}"
git config commit.gpgsign true
fi