Difference between revisions of "Linux gpg"
(One intermediate revision by the same user not shown) | |||
Line 68: | Line 68: | ||
To decrypt the file. | To decrypt the file. | ||
gpg -d filename | gpg -d filename | ||
+ | |||
+ | == Encrypt a File from user key == | ||
+ | |||
+ | Encrypt the file. | ||
+ | gpg --encrypt --user john.doe@email.com key.dv | ||
+ | |||
+ | decrypt the file to a bash variable. | ||
+ | export PGPASSWORD=$(cat $v_password | gpg --decrypt --user john.do@email.com) | ||
+ | |||
+ | == Extend the expiration date of a key == | ||
+ | If you key expires you can extend the expiration date of the key | ||
+ | |||
+ | Command | ||
+ | gpg --quick-set-expire {key_id} {extended_amount} | ||
+ | |||
+ | key_id=the key id | ||
+ | extended_amount=The amount of time to add, d, m, y | ||
+ | |||
+ | example | ||
+ | gpg --quick-set-expire 38D3CD66D0671E54B78001B43FD6190BCDE08D11 2y | ||
+ | |||
+ | https://www.gnupg.org/documentation/manuals/gnupg/OpenPGP-Key-Management.html |
Latest revision as of 10:50, 30 October 2024
Contents
Import Public/Private Key
It doesn't make a difference if its a private key or public key, this is the correct way to import a key.
gpg --import file.gpg
Export Public Key
This is the command to export your public key, using the armor command will convert the key from binary to ascii, so you can email it or post it.
gpg --armor --export you@example.com > mykey.asc
Another way
gpg --output mykey_pub.gpg --armor --export me@email.com
If you have more then one key another way where ABAACA is the hash.
gpg --output mykey_pub.gpg --armor --export ABAACA
Export a base64 output of your public key.
gpg --export me@email.com | base64
Export Private Key
To export your private key.
gpg --output mykey_sec.gpg --armor --export-secret-key me@email.com
another way, where ABAACA is the hash
gpg --output mykey_sec.gpg --armor --export-secret-key ABAACA
Base64 export of your private key.
gpg --export-secret-key me@email.com | base64
List Keys
To see a list of all the keys in the system.
gpg --list-keys
Sign a file
This will create a single file called text.sig that will contain both the file and the signature.
gpg --clear-sig --output text.sig text.txt
This will create a single file called text.sig that contains an ascii file with just the signature.
gpg --detach-sign --armor --output text.sig text.txt
This will create a single file called text.sig with a binary signature.
gpg --detach-sign --output text.sig text.txt
This will create an binary file with a signature and original document.
gpg --sign --output text.txt.sig text.txt
Backup
I read somewhere to back up the GPG file system, you can just copy ~/. gnupg but I have not tried this before.
Resources
https://www.debuntu.org/how-to-importexport-gpg-key-pair/
Encrypt a File with Password
To encrypt a file with a password with gpg use the following
gpg -c filename
This will create a new encrypted file with the extension .gpg, you can delete the unencrypted file.
To decrypt the file.
gpg -d filename
Encrypt a File from user key
Encrypt the file.
gpg --encrypt --user john.doe@email.com key.dv
decrypt the file to a bash variable.
export PGPASSWORD=$(cat $v_password | gpg --decrypt --user john.do@email.com)
Extend the expiration date of a key
If you key expires you can extend the expiration date of the key
Command
gpg --quick-set-expire {key_id} {extended_amount}
key_id=the key id extended_amount=The amount of time to add, d, m, y
example
gpg --quick-set-expire 38D3CD66D0671E54B78001B43FD6190BCDE08D11 2y
https://www.gnupg.org/documentation/manuals/gnupg/OpenPGP-Key-Management.html