https://wiki.archlinux.org/api.php?action=feedcontributions&user=N3hima&feedformat=atomArchWiki - User contributions [en]2024-03-28T12:50:00ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=GnuPG&diff=296432GnuPG2014-02-07T01:20:25Z<p>N3hima: /* Caff */ Changed SSMTP to msmtp because msmtp is actually maintained and generally better software</p>
<hr />
<div>[[Category:Security]]<br />
GnuPG can be used to sign and encrypt files or mails.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] {{Pkg|gnupg}}, available in the [[official repositories]].<br />
<br />
==Environment Variables==<br />
* {{ic|$GNUPGHOME}} is used by {{ic|GnuPGP}} to point to the directory where all configuration files are stored. By default {{ic|$GNUPGHOME}} isn't set and your {{ic|$HOME}} is used instead, thus you will find a {{ic|~/.gnupg}} directory right after the install. You may change this default setting by putting this line in one of your regular [[Startup_files|startup files]]<br />
export GNUPGHOME&#61;"/path/to/gnupg/directory"<br />
{{Note| by default, the gnupg directory has a particular [[Permissions]] set to ''600''. Only the owner of the directory has permission to read and write (''r'',''w''). This is for security purposes and should not be changed. In case this directory or any file inside it does not follow this security measure, you will get warnings about unsafe file and home directory permissions.}}<br />
* {{ic|GPG_AGENT_INFO}} used to loacte the pgp-agent. Consists of 3 colon delimited fields:<br />
**1. path to Unix Domain Socket<br />
**2. PID of gpg-agent<br />
**3. protocol version set to 1<br />
E.g : {{ic|GPG_AGENT_INFO&#61;/tmp/gpg-eFqmSC/S.gpg-agent:7795:1}}. When starting the gpg-agent, this variable is set to the correct value.<br />
<br />
==Configuration file==<br />
Default is {{ic|~/.gnupg/gpg.conf}}. If you want to change the default location, either run gpg this way {{ic|$ gpg --homedir ''path/to/file''}} or use {{ic|$GNUPGHOME}} variable.<br />
<br />
Append in this file any long options you want. Do not write the two dashes, but simply the name of the option and required arguments. You will find a skeleton file {{ic|usr/share/gnupg/gpg-conf.skel}}.<br />
Following is a basic configuration file:<br />
{{hc|~/.gnupg/gpg.conf|<br />
default-key ''name'' # useful in case you manage several keys and want to set a default one<br />
keyring ''file'' # will add ''file'' to the current list of keyrings<br />
trustdb-name ''file'' # use ''file'' instead of the default trustdb<br />
homedir ''dir'' # set the name of the gnupg home dir to ''dir'' instead of ~/.gnupg<br />
display-charset utf-8 # bypass all translation and assume that the OS uses native UTF-8 encoding<br />
keyserver ''name'' # use ''name'' as your keyserver<br />
no-greeting # suppress the initial copyright message<br />
armor # create ASCII armored output. Default is binary OpenPGP format<br />
}}<br />
<br />
If you want to set up default options for a multi-user system, the configuration file of defaults is expected in {{ic|/etc/skel/.gnupg/}}. With that in place the new user configuration can be created with <br />
# addgnupghome user1 user2 <br />
which will add the respective {{ic|/home/userX/.gnupg/}} and copy the files from the skeleton directory to it.<br />
<br />
== Basic keys management ==<br />
<br />
=== Create key ===<br />
<br />
* Set stronger algorithms to be used first:<br />
{{hc|~/.gnupg/gpg.conf|<br />
personal-digest-preferences SHA512<br />
cert-digest-algo SHA512<br />
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed<br />
}}<br />
<br />
* Generate a private key by typing in a terminal: <br />
$ gpg --gen-key<br />
<br />
You will be asked several questions. In general, most users will want both a RSA (sign only) and a RSA (encrypt only) key. It is advised to use a keysize of 4096 bits (default is 2048).<br />
<br />
While having an expiration date for subkeys isn't technically necessary, it is considered good practice. A period of a year is generally good enough for the average user. This way even if you lose access to your keyring, it will allow others to know that it is no longer valid.<br />
<br />
=== Manage your key ===<br />
* Running the {{ic|gpg --edit-key ''key ID''}} or {{ic|gpg --edit-key ''User_name_uid''}} command will present a menu which enables you to do most of your key management related tasks. Following is an example to set your expiration date:<br />
<br />
$ gpg --edit-key ''User_name_uid''<br />
> key ''number''<br />
> expire ''yyyy-mm-dd''<br />
> save<br />
> quit<br />
<br />
Some useful commands:<br />
> passwd # change the passphrase<br />
> clean # compact any user ID that is no longer usable (e.g revoked or expired)<br />
> revkey # revoke a key<br />
> addkey # add a subkey to this key<br />
<br />
* Generate an ASCII version of your public key (e.g. to distribute it by e-mail):<br />
$ gpg --armor --output public.key --export 'Your Name'<br />
<br />
* Register your key with a public PGP key server, so that others can retrieve your key without having to contact you directly:<br />
$ gpg --keyserver pgp.mit.edu --send-keys ''Key Id''<br />
<br />
* Sign and encrypt for user Bob<br />
$ gpg se -r Bob ''file''<br />
<br />
* make a clear text signature<br />
$ gpg --clearsign ''file''<br />
<br />
=== Rotating subkeys ===<br />
<br />
{{Warning|'''Never''' delete your expired or revoked subkeys unless you have a good reason. Doing so will cause you to lose the ability to decrypt files encrypted with the old subkey. Please '''only''' delete expired or revoked keys from other users to clean your keyring.}}<br />
<br />
If you have set your subkeys to expire after a set time, you will have to create new ones. Do this a few weeks in advanced to allow others to update their keyring.<br />
<br />
* Create new subkey (repeat for both signing and encrypting key)<br />
$ gpg --edit-key 'Your Name'<br />
> addkey<br />
<br />
And answer the following questions it asks (see previous section for suggested settings).<br />
<br />
* Save changes<br />
> save<br />
<br />
* Update it to a keyserver.<br />
$ gpg --keyserver pgp.mit.edu --send-keys ''Key Id''<br />
<br />
{{Note|Revoking expired subkeys is unnecessary and arguably bad form. If you are constantly revoking keys, it may cause others to lack confidence in you.}}<br />
<br />
=== Import key ===<br />
<br />
* Import a public key to your public key ring:<br />
$ gpg --import public.key<br />
<br />
* Import a private key to your secret key ring:<br />
$ gpg --import private.key<br />
<br />
=== List keys ===<br />
<br />
* Keys in your public key ring:<br />
$ gpg --list-keys<br />
<br />
* Keys in your secret key ring:<br />
$ gpg --list-secret-keys<br />
<br />
== Basic usage ==<br />
<br />
You can use gnupg to encrypt your sensitive documents, but only individual files at a time.<br />
<br />
For example, to decrypt a file, use:<br />
$ gpg -d secret.tar.gpg<br />
<br />
You'll be prompted to enter your passphrase.<br />
<br />
If you want to encrypt directories or a whole file-system you should consider using [[TrueCrypt]], though you can always tarball various files and then encrypt them.<br />
<br />
=== Symmetric Encryption ===<br />
<br />
== gpg-agent ==<br />
<br />
{{Ic|Gpg-agent}} is mostly used as daemon to request and cache the password for the keychain. This is useful if GnuPG is used from an external program like a mail client. It can be activated by adding following line in {{ic|~/.gnupg/gpg.conf}}:<br />
use-agent<br />
<br />
This tells GnuPG to use the agent whenever it needs the password. However, the agent needs to run already. To autostart it, create the following file and make it executable, and remember to change the envfile path if you changed your $GNUPGHOME:<br />
{{hc|/etc/profile.d/gpg-agent.sh|2=<nowiki><br />
if [ $EUID -ne 0 ] ; then<br />
envfile="$HOME/.gnupg/gpg-agent.env"<br />
if [[ -e "$envfile" ]] && kill -0 $(grep GPG_AGENT_INFO "$envfile" | cut -d: -f 2) 2>/dev/null; then<br />
eval "$(cat "$envfile")"<br />
else<br />
eval "$(gpg-agent --daemon --enable-ssh-support --write-env-file "$envfile")"<br />
fi<br />
export GPG_AGENT_INFO # the env file does not contain the export statement<br />
export SSH_AUTH_SOCK # enable gpg-agent for ssh<br />
fi<br />
</nowiki>}}<br />
<br />
If you don't want gpg-agent to autostart for all users or just want to keep user daemons in the users own configuration files you can add the following entry to your {{Ic|.xinitrc}}:<br />
eval $(gpg-agent --daemon) &<br />
<br />
Log out of your Xsession and log back in. Check if {{Ic|gpg-agent}} is activated<br />
$ pgrep agent<br />
<br />
==== Pinentry ====<br />
<br />
Finally, the agent needs to know how to ask the user for the password. This can be set in {{ic|~/.gnupg/gpg-agent.conf}}<br />
<br />
The default uses a gtk dialog. To change it to ncurses or qt, set the following in the above file<br />
<br />
pinentry-program /usr/bin/pinentry-curses<br />
<br />
or<br />
<br />
pinentry-program /usr/bin/pinentry-qt4<br />
<br />
For more options see {{Ic|man gpg-agent}} and {{ic|info pinentry}}.<br />
<br />
== Keysigning Parties ==<br />
To allow users to validate keys on the keyservers and in their keyrings (i.e. make sure they are from whom they claim to be), PGP/GPG uses a so-called "Web of Trust". To build this Web of Trust, many hacker events include keysigning parties.<br />
<br />
The [https://en.wikipedia.org/wiki/Zimmermann%E2%80%93Sassaman_key-signing_protocol Zimmermann-Sassaman] key-signing protocol is a way of making these very effective. [http://www.cryptnet.net/fdp/crypto/keysigning_party/en/keysigning_party.html Here] you'll find a How-To-article.<br />
<br />
=== Caff ===<br />
For an easier process of signing keys and sending signatures to the owners after a keysigning party, you can use the tool 'caff'. It can be installed from the AUR with the package {{AUR|caff-svn}} or bundled together with other useful tools in the package {{AUR|signing-party-svn}}.<br />
Either way, there will be a lot of dependencies installing from the AUR. Alternatively you can install them with<br />
cpanm Any:Moose<br />
cpanm GnuPG::Interface <br />
<br />
To send the signatures to their owners you need a working [https://en.wikipedia.org/wiki/Message_transfer_agent MTA]. If you don't have already one, install [[msmtp]].<br />
<br />
== Smartcards ==<br />
GnuPG uses scdaemon as an interface to your smartcard reader, please refer to {{Ic|scdaemon}} man page for details.<br />
<br />
=== GnuPG only setups===<br />
If you do not plan to use other cards but those based on GnuPG, you should check the {{Ic|reader-port}} parameter in {{ic|~/.gnupg/scdaemon.conf}}. The value '0' refers to the first available serial port reader and a value of '32768' (default) refers to the first USB reader.<br />
<br />
=== GnuPG together with OpenSC ===<br />
<br />
If you are using any smartcard with an opensc driver (e.g.: ID cards from some countries) you should pay some attention to GnuPG configuration. Out of the box you might receive a message like this when using {{Ic|gpg --card-status}}<br />
<br />
gpg: selecting openpgp failed: ec=6.108<br />
<br />
By default, scdaemon will try to connect directly to the device. This connection will fail if the reader is being used by another process. For example: the pcscd daemon used by OpenSC. To cope with this situation we should use the same underlying driver as opensc so they can work well together.<br />
In order to point scdaemon to use pcscd you should remove {{Ic|reader-port}} from {{ic|~/gnupg/scdaemon.conf}}, specify the location to libpcsclite.so library and disable ccid so we make sure that we use pcscd.<br />
<br />
{{hc|~/scdaemon.conf|<nowiki><br />
pcsc-driver /usr/lib/libpcsclite.so <br />
card-timeout 5<br />
disable-ccid<br />
</nowiki>}}<br />
<br />
Please check {{Ic|man scdaemon}} if you do not use OpenSC.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Su ===<br />
<br />
When using {{Ic|pinentry}}, you must have the proper permisions of the terminal device (e.g. {{Ic|/dev/tty1}}) in use. However, with {{Ic|su}} (or {{Ic|sudo}}), the ownership stays with the original user, not the new one. This means that pinentry will fail, even as root. The fix is to change the permissions of the device at some point before the use of pinentry (i.e. using gpg with an agent). If doing gpg as root, simply change the ownership to root right before using gpg<br />
chown root /dev/ttyN # where N is the current tty<br />
and then change it back after using gpg the first time. The equivalent is likely to be true with {{Ic|/dev/pts/}}. <br />
<br />
{{Note|being part of the group {{Ic|tty}} '''does not''' seem to alleviate the issue, at least as root. (Please confirm with non-superusers)}}<br />
<br />
=== Agent complains end of file ===<br />
<br />
The default pinentry program is pinentry-gtk-2, which needs a DBus session bus to run properly. See [[General Troubleshooting#Session permissions]] for details.<br />
<br />
Alternatively, you can use {{ic|pinentry-qt}}. See [[GnuPG#Pinentry]].<br />
<br />
=== KGpg configuration permissions ===<br />
<br />
There have been issues with {{Pkg|kdeutils-kgpg}} being able to access the {{ic|~/.gnupg/}} options. One issue might be a result of a deprecated ''options'' file, see the [https://bugs.kde.org/show_bug.cgi?id=290221 bug] report. <br />
<br />
Another user reported that ''KGpg'' failed to start until the {{ic|~/.gnupg}} folder is set to {{ic|drwxr-xr-x}} permissions. If you require this work-around, ensure that the directory contents retain {{ic|-rw-------}} permissions! Further, report it as a bug to the [https://bugs.kde.org/buglist.cgi?quicksearch=kgpg developers].<br />
<br />
== See also ==<br />
<br />
* [http://blog.sanctum.geek.nz/series/linux-crypto/ A more comprehensive gpg Tutorial]</div>N3hima