<p>Note: If gpg2 gives you error about invalid/unknown/etc. command, use gpg instead.</p>
<h2id="what-do-you-need">What do you need:?</h2>
<h3id="linux-debian-based-distributions">Linux (Debian based distributions)</h3>
<p>You need at least package gnupg, but I recommend installing packages icedove enigmail pinentry pinentry-curses pinentry-gtk2 pinentry-qt4 signing-party and gnupg2.</p>
<p>NOTE: If you aren't using Debian, install package "thunderbird" instead of "icedove".</p>
<h3id="mac-os-x">Mac OS X</h3>
<p>You need at least <ahref="http://www.gpgtools.org/">GPG-tools</a>, but I also recommend you to install <ahref="https://www.mozilla.org/en-US/thunderbird/">Thunderbird</a> and <ahref="Enigmail.html">Enigmail</a>.</p>
<h3id="windows">Windows</h3>
<p>You need at least <ahref="http://www.gpg4win.org/">GPG4Win</a>, but I recommend installing <ahref="https://www.mozilla.org/en-US/thunderbird/">Thunderbird</a> and <ahref="Enigmail.html">Enigmail</a> too.</p>
<h3id="step-1">Step 1</h3>
<p>This depends are you generating a new key or importing old key.</p>
<h4id="step-1-generating-a-new-key">Step 1: Generating a new key</h4>
<p>Open terminal (or cmd.exe if you are using Windows) and run</p>
<p>The second command also shows the key fingerprint which is usually used to identify the key. Note that you can see both keyid formats in fingerprint. The last eght characters in keyid are the short format and the last sixteen characters are the long format. If you want to see the long keyid, run</p>
<blockquote>
<p>gpg2 --list-keys --keyid-format long</p>
</blockquote>
<p>Now add the uid with the following commands:</p>
<blockquote>
<p>gpg2 --edit-key KEYID</p>
</blockquote>
<p>and enter command:</p>
<blockquote>
<p>adduid</p>
</blockquote>
<p>and you are asked for name and email address again. This time you can give them both.</p>
<p>If that UID which has only your first name isn't the first UID, select it by giving command, which is the number of the UID, for example:</p>
<blockquote>
<p>2</p>
</blockquote>
<p>and * appears to that UID to tell you that that UID is selected. Now give command</p>
<blockquote>
<p>primary</p>
</blockquote>
<p>to make it the primary UID again.</p>
<p>Now you can exit from GPG with</p>
<blockquote>
<p>quit</p>
</blockquote>
<p>and confirm to save changes with</p>
<blockquote>
<p>y</p>
</blockquote>
<h6id="setting-preferred-keyserver-of-the-key.">Setting preferred keyserver of the key.</h6>
<p>Preferred keyserver is where the key is refreshed when someone runs "gpg2 --refresh-keys".</p>
<p>To set it run</p>
<blockquote>
<p>gpg2 --edit-key KEYID</p>
</blockquote>
<blockquote>
<p>keyserver</p>
</blockquote>
<p>and enter the keyserver address, for example hkp://pool.sks-keyservers.net (I recommend this keyserver).</p>
<h4id="step-1-importing-old-key">Step 1: Importing old key</h4>
<p>You can import your old private key same way as you import public keys. This means:</p>
<blockquote>
<p>gpg2 --import key.asc</p>
</blockquote>
<p>Where key.asc is the file, which contains the (private) key(s)</p>
<h3id="step-2-backing-up-the-key">Step 2: backing up the key</h3>
<p>You need to know your keyid. I told you how to get it in "Adding new uids". To back up your private key, run</p>
<blockquote>
<p>gpg2 --export-secret-keys -a KEYID</p>
</blockquote>
<p>and save the output of that command to file. If you are on Linux or Mac OS X, you can forward the output directly to file, with</p>
<blockquote>
<p>gpg2 --export-secret-keys -a KEYID > privatekey.asc</p>
</blockquote>
<p>The previous command creates a file called "privatekey.asc", which contains the output of the first command.</p>
<p>The configuring of gpg happens in gpg configuration directory. In Linux and Mac this is ~/.gnupg/gpg.conf.</p>
<p>I recommend you to add following lines to it. I'll try to explain them with my best ability.</p>
<p><code># Options for GnuPG # Copyright 1998, 1999, 2000, 2001, 2002, 2003, # 2012— Mika Suomalainen (Mkaysi) https://raw.github.com/Mkaysi/shell-things/master/gnupg/gpg.conf # 2010 Free Software Foundation, Inc. # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This file is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</code> License information so I won't break license of the default config file, which I have appended.</p>
<blockquote>
<p>default-key KEYID</p>
</blockquote>
<p>So KEYID is used by default if there are multiple secret keys.</p>
<pre><code>default-recipient-self
encrypt-to KEYID</code></pre>
<p>So everything what you encrypt is also encrypted to you.</p>
<blockquote>
<p>keyid-format 0xLONG</p>
</blockquote>
<p>So keyids are shown in the longest format, including 0x prefix, which marks them as hexadecimanls.</p>
<p>Example outputs from --list-keys and gpg --fingerprint after setting 0xLONG as keyid format.</p>
<p>After you set 0xLONG as keyid-format, keys appear like 0x4DB53CFE82A46728 instead of 82A46728.</p>
<blockquote>
<p>charset UTF-8</p>
</blockquote>
<p>So UTF-8 is used as default character set and most of characters can be used.</p>
<blockquote>
<p>armor</p>
</blockquote>
<p>So you don't need to specify -a to get ASCII armoured text.</p>
<p>So default keyserver is specified and unknown keys are always received when something what requires missing key is procressses and revoked keys aren't included in search results and verbose output is used and signatures by unknown keys are automatically removed.</p>
<p>By the way, you can find my gpg.conf <ahref="https://raw.github.com/Mkaysi/shell-things/master/gnupg/gpg.conf">here</a>.</p>
<h4id="group-lines">Group lines</h4>
<p>Group lines are a way to write email to one recepient and have it encrypted to multiple keys automatically.</p>
<p>With that line, when recepient is touchlay-server@googlegroups.com, then emails are encrypted to those 4 keys.</p>
<p>NOTE: KEYIDs in group line should be in format 0xLONG. If you don't use that format by default, use "gpg2 --keyid-format 0xLONG --list-keys".</p>
<p>See also my <ahref="Enigmail.html">Enigmail</a> instructions about group lines.</p>
<h3id="comments">Comments</h3>
<p>GPG can automatically add comments to signed and encrypted content. They are usually hidden by email clients, which support GPG.</p>
<p>If you have homepage, it's recommended that you put your key there. My key can be found at <ahref="../../PGP/key.txt">PGP/key.txt</a></p>
<p>You can get your public key with command</p>
<blockquote>
<p>gpg2 --export -a KEYID</p>
</blockquote>
<p>or if you use Linux and have installed package signing-party, you can use</p>
<blockquote>
<p>pgp-clean KEYID</p>
</blockquote>
<p>to get your public key without signatures (I will explain them later). WARNING: pgp-clean seems to also remove encryption subkey.</p>
<h4id="with-keyservers">With keyservers</h4>
<p>If you followed my configuration, you are usng pool.sks-keyservers.net as your keyserver and you are automatically receiving unknown keys from t, whenever you try to verify something, what is signed with unknown key.</p>
<p>To send your public key to keyserver, run</p>
<blockquote>
<p>gpg2 --send-keys KEYID</p>
</blockquote>
<p>To receive key from keyserver, run</p>
<blockquote>
<p>gpg2 --recv-keys KEYID</p>
</blockquote>
<p>To search keys from keyserver, use</p>
<blockquote>
<p>gpg2 --search-keys QUERY WORDS</p>
</blockquote>
<p>or if you are using Linux and have packages signing-party and dialog installed, you can use</p>
<blockquote>
<p>keylookup QUERY WORDS</p>
</blockquote>
<h5id="word-of-warning">Word of warning</h5>
<p>Keyservers only append content. Information on keyserver cannot be removed. This means, that when you delete uid, signature or whatever, it reappears when you run</p>
<blockquote>
<p>gpg2 --refresh-keys</p>
</blockquote>
<p>or receive your key from keyserver again. Thought content (uids, signatures, keys etc.) can be revoked.</p>
<h1id="you-can-now-move-to-icedove-thunderbird-guide-and-after-that-or-enigmail-guide-because-things-after-this-are-usually-done-by-email-client.">You can now move to Icedove / Thunderbird guide and after that | or Enigmail guide, because things after this are usually done by email client.</h1>
<p>But you should continue reading to understand how to use GPG without email client.</p>
<h2id="trusting-keys.">Trusting keys.</h2>
<p>If you want to make gpg know that you trust key of another person, you have two opinons. Enter the "key editing shell", with</p>
<blockquote>
<p>gpg2 --edit-key KEYID</p>
</blockquote>
<p>and</p>
<h3id="way-1-lsign">Way 1: lsign</h3>
<p>Lsign signs the key locally making it impossible to export the signature. Use it if you trust the key owner to be who the key says, but you haven't met him/her personally.</p>
<p>Lsign the key with</p>
<blockquote>
<p>lsign</p>
</blockquote>
<p>and then you can exit gpg with</p>
<blockquote>
<p>quit</p>
</blockquote>
<p>confirming to svae changes with</p>
<blockquote>
<p>y</p>
</blockquote>
<h3id="way-2-sign">Way 2: sign</h3>
<p>If you trust the key owner to be whom the key says and you have met him/her personally and have seen proof of his/her identify (i.e. passport) or he/she is member of your family or long time friend, you can sign the key with</p>
<blockquote>
<p>sign</p>
</blockquote>
<p>making the signature exportable or sendable to keyserver. Now exit gpg with</p>
<blockquote>
<p>quit</p>
</blockquote>
<p>saving the changes with</p>
<blockquote>
<p>y</p>
</blockquote>
<p>and send the signed key to keyserver with</p>
<blockquote>
<p>gpg2 --send-keys KEYID</p>
</blockquote>
<p>Other people will see your signature next time when they receive the key agan or run</p>
<blockquote>
<p>gpg2 --refresh-keys</p>
</blockquote>
<p>NOTE: You can upgrade lsigned signature to signed signature with the "sign" command.</p>
<h4id="trust">Trust</h4>
<p>Trust determines does gpg trust the key to validate other keys. Trust is only visible to you. You can se trust with</p>
<blockquote>
<p>trust</p>
</blockquote>
<p>and then exit gpg with</p>
<blockquote>
<p>quit</p>
</blockquote>
<p>saving the changes with</p>
<blockquote>
<p>y</p>
</blockquote>
<h2id="signing">Signing</h2>
<h3id="signing-a-message">Signing a message</h3>
<p>Run</p>
<blockquote>
<p>gpg2 --clearsign</p>
</blockquote>
<p>and write your message. When you are ready, add one empty line and press CTRL-D and gpg outputs signed message.</p>
<h3id="signing-a-plaintext-file">Signing a plaintext file</h3>
<p>Just run</p>
<blockquote>
<p>gpg2 --clearsign file.txt</p>
</blockquote>
<p>and the signed content will be found from file.txt.asc</p>
<p>NOTE: .asc is same as .txt and can be opened with normal text editor.</p>
<p>gpg2 --encrypt -a -r receiver (-r receiver...)</p>
</blockquote>
<p>If you followed my configuration instructions, you are automatically receiver. Replace "receiver" with KEYID. Write your message, add empty line and press CTRL-D and gpg outputs encrypted content.</p>
<h3id="decrypting">Decrypting</h3>
<p>Just run</p>
<blockquote>
<p>gpg2 --decrypt</p>
</blockquote>
<p>paste the encrypted content, add empty line and press CTRL-D and gpg outputs, the decrypted content.</p>
<h2id="read-also">Read also</h2>
<p>My <ahref="../Thunderbird-Icedove.html">Icedove / Thunderbird guide</a> and <ahref="Enigmail.html">Enigmail guide</a>.</p>
<h2id="license">License</h2>
<p><arel="license"href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><imgalt="Creative Commons License"style="border-width:0"src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png"/></a><br/><spanxmlns:dct="http://purl.org/dc/terms/"property="dct:title">GPG guide</span> by <axmlns:cc="http://creativecommons.org/ns#"href="http://mkaysi.github.com/articles/guides/GPG/GPG.html"property="cc:attributionName"rel="cc:attributionURL">Mika Suomalainen</a> is licensed under a <arel="license"href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.</p>