Commands tagged GPG (30)

  • Very useful in shell scripts because you can run a task nicely in the background using job-control and output progress until it completes. Here's an example of how I use it in backup scripts to run gpg in the background to encrypt an archive file (which I create in this same way). $! is the process ID of the last run command, which is saved here as the variable PI, then sleeper is called with the process id of the gpg task (PI), and sleeper is also specified to output : instead of the default . every 3 seconds instead of the default 1. So a shorter version would be sleeper $!; The wait is also used here, though it may not be needed on your system. echo ">>> ENCRYPTING SQL BACKUP" gpg --output archive.tgz.asc --encrypt archive.tgz 1>/dev/null & PI=$!; sleeper $PI ":" 3; wait $PI && rm archive.tgz &>/dev/null Previously to get around the $! not always being available, I would instead check for the existance of the process ID by checking if the directory /proc/$PID existed, but not everyone uses proc anymore. That version is currently the one at but I plan on upgrading to this new version soon. Show Sample Output

    AskApache · 2009-09-21 07:36:25 1
  • According to the gpg(1) manual: --gen-random 0|1|2 count Emit count random bytes of the given quality level 0, 1 or 2. If count is not given or zero, an endless sequence of random bytes will be emitted. If used with --armor the output will be base64 encoded. PLEASE, don't use this command unless you know what you are doing; it may remove precious entropy from the system! If your entropy pool is critical for various operations on your system, then using this command is not recommended to generate a secure password. With that said, regenerating entropy is as simple as: du -s / This is a quick way to generate a strong, base64 encoded, secure password of arbitrary length, using your entropy pool (example above shows a 30-character long password). Show Sample Output

    gpg --gen-random --armor 1 30
    atoponce · 2011-07-20 15:32:49 2
  • (Please see sample output for usage) Use any script name (the read command gets it) and it will be encrypted with the extension .crypt, i.e.: myscript --> myscript.crypt You can execute myscript.crypt only if you know the password. If you die, your script dies with you. If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string). Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to ), but not enough space to do it on a one liner. Sorry for the chmod on parentheses, I dont like "-" at the end. Thanks flatcap for the subshell abbreviation to /dev/null Show Sample Output

    rodolfoap · 2013-03-10 08:59:45 9
  • (Please see sample output for usage) script.bash is your script, which will be crypted to script.bash --> You can execute only if you know the password. If you die, your script dies with you. If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string). Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to ), but not enough space to do it on a one liner. Show Sample Output

    echo "eval \"\$(dd if=\$0 bs=1 skip=XX 2>/dev/null|gpg -d 2>/dev/null)\"; exit" >; sed -i s:XX:$(stat -c%s; gpg -c < script.bash >>; chmod +x
    rodolfoap · 2013-03-09 11:16:48 5

    sh <(curl
    lrvick · 2015-03-15 21:02:01 2

    AskApache · 2009-08-18 07:03:08 0

    slashdot · 2009-10-19 20:38:37 0

    kaiserkailua · 2011-02-23 14:19:08 2

    lingo · 2011-07-22 16:31:25 2
  • In this example, where the users gpg keyring has a password, the user will be interactively prompted for the keyring password. If the keyring has no password, same as above, sans the prompt. Suitable for cron jobs. ~/.gnupg/passwd/http-auth.gpg is the encrypted http auth password, for this particular wget use case. This approach has many use cases. example bash functions: function http_auth_pass() { gpg2 --decrypt ~/.gnupg/passwd/http-auth.gpg 2>/dev/null; } function decrypt_pass() { gpg2 --decrypt ~/.gnupg/passwd/"$1" 2>/dev/null; }

    kyle0r · 2012-12-13 00:14:55 0

    x=KEY; gpg --keyserver --recv $x; gpg --export --armor $x | sudo apt-key add -
    sxiii · 2013-11-26 10:49:32 0
  • From time to time one forgets either thier gpg key or other passphrases. This can be very problematic in most cases. But luckily there's this script. Its based off of pwsafe which is a unix commandline program that manages encrypted password databases. For more info on pwsafe visit, What this script does is it will help you store all your passphrases for later on and allow you to copy it to your clipboard so you can just paste it in, all with one password. Pretty neat no? You can find future releases of this and many more scripts at The Teachings of Master Denzuko - Show Sample Output

    denzuko · 2009-05-07 14:49:56 0
  • Make sure the file contents can't be retrieved if anyone gets ahold of your physical hard drive. With hard drive partition: gpg --default-recipient-self -o /path/to/encrypted_backup.gpg -e /dev/sdb1 && shred -z /dev/sdb1 WARNING/disclaimer: Be sure you... F&%k it--just don't try this.

    h3xx · 2011-07-24 05:51:47 0

  • 0
    gpg -c file.txt
    kev · 2011-09-17 04:53:03 0

  • 0
    gpg -c sensitive.txt; gpg sensitive.txt.gpg
    evandrix · 2012-09-05 22:52:26 0
  • Shows a sigclass 0x20 (Key revocation) signature packet on a key, including all subpackets. Subpacket 2 is the date of revocation, subpacket 26 the relevant policy, subpacket 29 the reason of revocation (cf. ) and subpacket 16 the issuer of the revocation certificate (usually should be the same as the revoked key). Show Sample Output

    claudius · 2013-03-05 14:11:11 1
  • The original command doesn't work for me - does something weird with sed (-r) and xargs (-i) with underscores all over... This one works in OSX Lion. I haven't tested it anywhere else, but if you have bash, gpg and perl, it should work. Show Sample Output

    hank · 2013-03-10 09:15:15 1
  • Decrypt with: gpg -o- foo.tgz.gpg | tar zxvf -

    skkzsh · 2013-03-13 09:44:39 0
  • Need to encrypt something from the command line? I've used this before to encrypt passwords with a master password that was shared amongst a team. To decrypt: ~$ echo -n 'jA0EAwMCPdknsznAww5gySL1/quqhXg6QgQkIz5abzGP5EZgTbXCFU+y6dP8ySWovytc' | base64 --decode | gpg --decrypt gpg: CAST5 encrypted data Enter passphrase: secret gpg: encrypted with 1 passphrase HelloWorld! Show Sample Output

    echo 'HelloWorld!' | gpg --symmetric | base64
    ryanchapman · 2013-07-06 08:30:35 0
  • The subject in a gpg mail isn't encrypted. For people without imagination this often becomes a drama. Requirement: 1. Install polygen sudo apt-get install polygen 2. Download "Bastard Operator From Hell Excuses" dictionary: cd ~/.icedove/xxxxxxx.default/ && wget Show Sample Output

    vinc3nt · 2013-10-08 16:29:16 0
  • This will list all the gpg keys that were accepted and installed for yum. Show Sample Output

    krizzo · 2014-12-09 21:23:28 0
  • This will remove the gpg-pubkey-1aa043b8-53b2e946 from rpm/yum and you'll be prompted to add it back from the given repo. Show Sample Output

    krizzo · 2014-12-09 21:27:08 0

  • 0
    tar --create --file - | gpg --encrypt --recipient --output .tar.gpg
    plivox · 2016-01-15 16:41:44 0
  • Requires: signing-party (on Debian). Note: you need a working MTA on your machine.

    caff <keyid>
    raphink · 2009-02-18 14:09:03 0
  • echo "ls" > script.bash; This is my script, a simple 'ls'. gpg -c script.bash; Here I encrypt and passord-protect my script. This creates file script.bash.gpg. cat script.bash.gpg | gpg -d --no-mdc-warning | bash Here I open file script.bash.gpg, decrypt it and execute it.

    betsubetsu · 2013-03-10 09:34:12 1
  •  1 2 > 


Share Your Commands

Check These Out

List all NPM global packages installed

Rename files in batch

Extract all GPS positions from a AVCHD video.

Spoof your wireless MAC address on OS X to 00:e2:e3:e4:e5:e6
If you want to check that the spoof worked, type the same command as earlier: $ifconfig en1 | grep ether Now you will see: $ether 00:e2:e3:e4:e5:e6 For the wired ethernet port: $sudo ifconfig en0 ether 00:e2:e3:e4:e5:e6

Delete specific sender in mailq

make 100 directories with leading zero, 001...100, using bash3.X

Create .pdf from .doc
sudo apt-get install wv tetex-extra ghostscript

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

diff the same file in two directories.
This is useful when you're diffing two files of the same name in radically different directory trees. For example: Set $ path1='/some/long/convoluted/path/to/all/of/your/source/from/a/long/dead/machine' then $ path2='/local/version/of/same/file' then run the command. Much easier on the eyes when you're looking back across your command history, especially if you're doing the same diff over and over again.

list block devices

Stay in the loop…

Follow the Tweets.



Subscribe to the feeds.


Subscribe to the feed for: