Skip to content

Instantly share code, notes, and snippets.

@MarkusH
Created September 21, 2016 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkusH/9fb1465f92e7b337b8034491e7865b90 to your computer and use it in GitHub Desktop.
Save MarkusH/9fb1465f92e7b337b8034491e7865b90 to your computer and use it in GitHub Desktop.
Check if GPG key is expiring soon (next 30 days)
#!/usr/bin/sh
test $(($((`gpg --with-colons --fixed-list-mode --list-keys 0xAFE79D68D41C7E39 | egrep '^(pub|sub):' | cut -d: -f7 | sort | head -n 1` - `date +"%s"`))/86400)) -le 30 && echo "expiring soon" || echo "still good"
@MarkusH
Copy link
Author

MarkusH commented Sep 21, 2016

Formatted:

test $(($(( \
  `gpg --with-colons --fixed-list-mode --list-keys 0xAFE79D68D41C7E39 \
  | egrep '^(pub|sub):' \
  | cut -d: -f7 \
  | sort \
  | head -n 1` \
  - `date +"%s"` \
))/86400)) -le 30 \
&& echo "expiring soon" \
|| echo "still good"

@MarkusH
Copy link
Author

MarkusH commented Sep 21, 2016

Renew key with:

$ gpg --edit-key 0xAFE79D68D41C7E39
gpg> key 0
gpg> expire
Key is valid for? (0) 1y
Is this correct? (y/N) y
gpg> key 1
gpg> expire
Key is valid for? (0) 1y
Is this correct? (y/N) y
gpg> save
$ gpg --send-keys 0xAFE79D68D41C7E39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment