Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # GPG
- <!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
- - [GPG](#gpg)
- - [Create keys](#create-keys)
- - [List keys](#list-keys)
- - [Exporting](#exporting)
- - [Importing](#importing)
- - [Deleting](#deleting)
- - [Fingerprint](#fingerprint)
- - [Encrypting data](#encrypting-data)
- - [Decrypting data](#decrypting-data)
- - [Sharing secret keys](#sharing-secret-keys)
- <!-- /TOC -->
- ## Create keys
- You can select the defaults.
- ```bash
- gpg --gen-key
- ```
- ## List keys
- __Public keys__
- ```bash
- gpg --list-keys
- ```
- __Secret keys__
- ```bash
- gpg --list-secret-keys
- ```
- ## Exporting
- __Public key__
- ```bash
- gpg --export -a "UserName" > gpg.public.key
- ```
- > Hint: instead "UserName" you can type email or GPG id
- __Secret key__
- ```bash
- gpg --export-secret-key -a "name@domain.com" > gpg.secret.key
- ```
- > Hint: instead "name@domain.com" you can type user name or GPG id
- ## Importing
- __Public key__
- ```bash
- gpg --import gpg.public.key
- ```
- __Secret key__
- ```bash
- gpg --allow-secret-key-import --import gpg.secret.key
- ```
- ## Deleting
- __Public key__
- ```bash
- gpg --delete-key "User Name"
- ```
- > Hint: Instead "User Name" you can type GPG id or email
- __Secret key__
- ```bash
- gpg --delete-secret-key 35E82649
- ```
- > Hint: Instead 35E82649 (GPG id) you can type user name or email
- ## Fingerprint
- To generate a short list of numbers that you can use via an alternative method to verify a public key, use:
- ```bash
- gpg --fingerprint > gpg.fingerprint
- ```
- This creates the file fingerprint with your fingerprint info.
- ## Encrypting data
- To encrypt data, use:
- ```bash
- gpg -e -u "Sender User Name" -r "Receiver User Name" mydata.tar
- ```
- > Hint: Instead typing user name of sender and receiver, you can type email
- There are some useful options here, such as -u to specify the secret key to be used, and -r to specify the public key of the recipient.
- As an example: gpg -e -u "Charles Lockhart" -r "A Friend" mydata.tar
- This should create a file called "mydata.tar.gpg" that contains the encrypted data. I think you specify the senders username so that the recipient can verify that the contents are from that person
- > NOTE!: mydata.tar is not removed, you end up with two files, so if you want to have only the encrypted file in existance, you probably have to delete mydata.tar yourself.
- An interesting side note, I encrypted the preemptive kernel patch, a file of 55,247 bytes, and ended up with an encrypted file of 15,276 bytes.
- ## Decrypting data
- To decrypt data, use:
- ```bash
- gpg -d mydata.tar.gpg
- ```
- If you have multiple secret keys, it'll choose the correct one, or output an error if the correct one doesn't exist. You'll be prompted to enter your passphrase. Afterwards there will exist the file "mydata.tar", and the encrypted "original," mydata.tar.gpg.
- > NOTE: when I originally wrote this cheat sheet, that's how it worked on my system, however it looks now like "gpg -d mydata.tar.gpg" dumps the file contents to standard output. The working alternative (worked on my system, anyway) would be to use "gpg -o outputfile -d encryptedfile.gpg", or using mydata.tar.gpg as an example, I'd run "gpg -o mydata.tar -d mydata.tar.gpg". Alternatively you could run something like "gpg -d mydata.tar.gpg > mydata.tar" and just push the output into a file. Seemed to work either way.
- Ok, so what if you're a paranoid bastard and want to encrypt some of your own files, so nobody can break into your computer and get them? Simply encrypt them using yourself as the recipient.
- ## Sharing secret keys
- > NOTE!: the following use cases indicate why the secret-key import/export commands exist, or at least a couple ideas of what you could do with them. HOWEVER, there's some logistics required for sharing that secret-key. How do you get it from one computer to another? I guess encrypting it and sending it by email would probably be ok, but I wouldn't send it unencrypted with email, that'd be DANGEROUS.
- Use Case *.1 : Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically if you want one key-pair for all of your computers (assuming you have multiple computers), then this allows you export that key-pair from the original computer and import it to your other computers.
- Use Case *.2 : Mentioned above were the commands for exporting and importing secret keys, and I want to explain one reason of why maybe you'd want to do this. Basically, if you belonged to a group, and wanted to create a single key-pair for that group, one person would create the key-pair, then export the public and private keys, give them to the other members of the group, and they would all import that key-pair. Then a member of the group or someone outside could use the group public key, encrypt the message and/or data, and send it to members of the group, and all of them would be able to access the message and/or data. Basically you could create a simplified system where only one public key was needed to send encrypted stuffs to muliple recipients.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement