-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpg_key_generator.sh
47 lines (41 loc) · 1.28 KB
/
gpg_key_generator.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
echo '-- Generating entropy'
sudo dd if=/dev/sda of=/dev/null &
TASK_PID=$!
# Batch file with GPG Key parameters
# If not entered Passphrase this way, then dialog to ask for a passphrase will pop-up
cat > gpgparams <<EOF
Key-Type: RSA
Key-Length: 4096
Key-Usage: encrypt
Subkey-Type: RSA
Subkey-Length: 4096
Subkey-Usage: encrypt
Name-Real: User Name
Name-Comment: none
Name-Email: user@server
Expire-Date: 0
Passphrase: hellisreal
%pubring userserver.pub
%secring userserver.sec
%commit
%echo done
EOF
# Generating keys according the bath file
echo '-- Generating keys'
gpg --no-tty --no-permission-warning --homedir . --batch --gen-key gpgparams 2>&1
echo "Result: $?"
echo "Files:"
ls -al
echo && echo '-- Killing entropy generator'
sudo kill $TASK_PID
echo && echo '-- Listing keys'
gpg --homedir . --no-default-keyring --secret-keyring ./userserver.sec --keyring ./userserver.pub --list-secret-keys
# no-default-keyring — do not add the default keyrings to the list of keyrings
# secret-keyring — add a secret keyring ./userserver.sec
echo && echo '-- exporting public key'
gpg --homedir . --no-default-keyring --secret-keyring ./userserver.sec --keyring ./userserver.pub --export -a user@server > pubkey.txt 2>&1
echo "Files:"
ls -al
echo "Content of public key:"
cat pubkey.txt