pages tagged not http://meng6net.localhost/tag/not/ <p><small>Copyright © 2005-2020 by <code>Meng Lu &lt;lumeng3@gmail.com&gt;</code></small></p> Meng Lu's home page ikiwiki Tue, 16 May 2017 23:59:39 +0000 Installing and configuring gpg http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_gpg/ http://meng6net.localhost/computing/installing_and_configuring/installing_and_configuring_gpg/ computing configuration documentation installation not software Tue, 16 May 2017 23:59:39 +0000 2017-05-16T23:59:39Z <h2>Install GnuPG</h2> <h3>Macports</h3> <pre><code>$ sudo port install gnupg &lt;snip&gt; $ which gpg /opt/local/bin/gpg </code></pre> <p>There is also a <code>gnupg2</code> which provides S/MIME support and <code>gpg-agent</code> and extended smartcard support.</p> <pre><code>$ sudo port install gnupg2 </code></pre> <h3>Homebrew</h3> <pre><code>$ brew install gnupg $ brew install gnupg2 </code></pre> <h2>Generate public and private keys</h2> <pre><code>$ gpg --gen-key gpg (GnuPG) 1.4.11; Copyright (C) 2010 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) Requested keysize is 2048 bits Please specify how long the key should be valid. 0 = key does not expire &lt;n&gt; = key expires in n days &lt;n&gt;w = key expires in n weeks &lt;n&gt;m = key expires in n months &lt;n&gt;y = key expires in n years Key is valid for? (0) Key does not expire at all Is this correct? (y/N) y You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;" Real name: Foo Bar Email address: foo@bar.com Comment: You selected this USER-ID: "Foo Bar &lt;foo@bar.com&gt;" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O You need a Passphrase to protect your secret key. We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. ..........+++++ ..+++++ We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. ................+++++ ...+++++ gpg: /home/usr1/foo/.gnupg/trustdb.gpg: trustdb created gpg: key 306807EF marked as ultimately trusted public and secret key created and signed. gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u pub 2048R/306807EF 2011-06-05 Key fingerprint = 4D7E 594E 626D A51E 87C7 0419 704A 04B0 3068 07EF uid Foo Bar &lt;foo@bar.com&gt; sub 2048R/A793EF59 2011-06-05 $ </code></pre> <h2>Set GPGKEY environment variable in .bashrc</h2> <p>Add export GPGKEY=306807EF to <code>~/.bashrc</code>.</p> <p>Restart the <code>gpg-agent</code> and source <code>.bashrc</code> to activate the <code>GPGKEY</code>:</p> <pre><code>$ killall -9 gpg-agent $ eval $(gpg-agent --daemon) gpg-agent[48390]: directory `/Users/foobaruser/.gnupg' created gpg-agent[48390]: directory `/Users/foobaruser/.gnupg/private-keys-v1.d' created gpg-agent[48391]: gpg-agent (GnuPG) 2.0.17 started $ source ~/.bashrc </code></pre> <h2>Configure GnuPG with <code>~/.gnupg/gpg.conf</code></h2> <h3>Adding key servers</h3> <pre><code>keyserver hkp://keys.gnupg.net keyserver hkp://pool.sks-keyservers.net # C.f. http://en.wikipedia.org/wiki/Key_server_(cryptographic) for a list of key servers keyserver hkp://subkeys.pgp.net keyserver hkp://pgp.mit.edu #keyserver hkp://keys.nayr.net </code></pre> <h2>Export ASCII-armored version of your public key</h2> <pre> <code>$ gpg --armor --output fooatbardotcom_public_key.asc --export foo@bar.com $ ls fooatbardotcom_public_key.asc </code></pre> <p>Put the <code>fooatbardotcom_public_key.asc</code> on your website, in your Dropbox, or send it to other people.</p> <h2>Publish your key to key severs, website, etc.</h2> <h3>To your homepage</h3> <ul> <li>display ASCII-armored version of your PGP public key</li> <li>give link to trust path and statistics <code>http://pgp.cs.uu.nl/stats/XXX.html</code> where XXX is your key ID</li> </ul> <h3>To a key server via command line</h3> <pre> <code>$ gpg --send-keys --keyserver hkp://subkeys.pgp.net $GPGKEY gpg: sending key 306807EF to hkp server subkeys.pgp.net gpg: keyserver timed out gpg: keyserver send failed: keyserver error </code></pre> <p>Key servers: http://pgp.surfnet.nl:11371/ hkp://subkeys.pgp.net hkp://pgp.mit.edu http://keys.gnupg.net</p> <h3>To a key server via web browser</h3> <ul> <li>Visit <code>http://keys.gnupg.net/</code> in a browser.</li> <li>Paste the content of <code>fooatbardotcom_public_key.asc</code> into the text field in "Submit a key" section of the page, and click "Submit this key to the keyserver!"</li> </ul> <h2>Get your key signed so you are in the "strongly connected set"</h2> <ul> <li> <p>visit <code>http://www.biglumber.com/</code></p> </li> <li> <p>add your public key to the server</p> </li> <li> <p>request a login token, it will be encrypted and sent to the email associated with the public key.</p> </li> <li> <p>Check email from <code>spider@biglumber.com</code>; Download it. It is just a file called <code>noname</code>. You can view it with <code>more</code> or a text editor. It looks like</p> <pre> <code> hQEMA3TQ0Htyb4f8AQf/dGI5l8akLVAccu3zTTurEkoqVvZo3iWa7uAeZ+OsUuW9 Ev0XKnTFKrEUd0sI1LebZfuQv13no/3FweppVuqYAInRxdc2U4fANhNkEpmTNjI2 ... </code></pre></li> <li> <p>Decrypt it</p> <pre><code> $ gpg --decrypt ./noname You need a passphrase to unlock the secret key for user: "Foo Bar &lt;barfoo@gmail.com&gt;" 2048-bit RSA key, ID XXXXXXXX, created 2011-06-04 (main key ID XXXXXXXX) gpg: encrypted with 2048-bit RSA key, ID XXXXXXXX, created 2011-06-04 "Foo Bar &lt;barfoo@gmail.com&gt;" Someone (hopefully you) has just requested that we email a login token for bigbarmber.com to the owner of this key: Name: Foo Bar Fingerprint: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Email: barfoo@gmail.com You can now login to the site and add, edit, or delete listings by visiting the URL below and entering your password: http://bigbarmber.com/x/web?enter=1 Password: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX If you did NOT make this request, then somebody is abusing the system and we would like to know about it. This is the information we have about the request: IP: XXX.XXX.XXX.XXX HOST: 221.205.177.140.in-addr.arpa domain name pointer proxy3.bar.com. BROWSER: Mozilla/5.0 (Macintosh; Intel macOS 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24 TIME: Sat Jun 4 22:59:10 2011 (GMT) Please email abuse@bigbarmber.com if this is the case. Otherwise, email us at help@bigbarmber.com with any questions or problems. You can also use the feedback link at the site instead of the emails above, if you wish. Please sign any correspondance (clearsign preferred) to verify yourself as owner of the key. Thanks and enjoy, bigbarmber.com </code></pre></li> <li> <p>Use the password and URL to login and add your listing (name, country, city, URL). After that you should have a listing page <code>http://bigbarmber.com/x/web?sn=Foo+Bar</code></p> </li> <li> <p>Find someone close to sign keys. Physically meet the person, verify his/her identity, then sign his/her public key. See <a href= "https://help.ubuntu.com/community/GnuPrivacyGuardHowto#Getting%20your%20key%20signed"> Ubuntu Documentation: GnuPrivacyGuardHowto</a>.</p> </li> </ul> <h2>Export revocation key</h2> <pre> <code>$ gpg --output fooatbardotcom_revoke_key.asc --gen-revoke $GPGKEY sec 2048R/306807EF 2011-06-05 Foo Bar &lt;foo@bar.com&gt; Create a revocation certificate for this key? (y/N) y Please select the reason for the revocation: 0 = No reason specified 1 = Key has been compromised 2 = Key is superseded 3 = Key is no longer used Q = Cancel (Probably you want to select 1 here) Your decision? 1 Enter an optional description; end it with an empty line: &gt; Reason for revocation: Key has been compromised (No description given) Is this okay? (y/N) y You need a passphrase to unlock the secret key for user: "Foo Bar &lt;foo@bar.com&gt;" 2048-bit RSA key, ID 306807EF, created 2011-06-05 ASCII armored output forced. Revocation certificate created. Please move it to a medium which you can hide away; if Mallory gets access to this certificate he can use it to make your key unusable. It is smart to print this certificate and store it away, just in case your media become unreadable. But have some caution: The print system of your machine might store the data and make it available to others! $ </code></pre> <h2>Back up your keys</h2> <pre><code>$ gpg --list-keys $ gpg -ao fooatbardotcom_public_key.asc --export $GPGKEY $ gpg --list-secret-keys $ gpg -ao fooatbardotcom_private_key.asc --export-secret-keys $GPGKEY $ gpg -ao fooatbardotcom_revoke_key.asc --gen-revoke $GPGKEY $ gpg --export-ownertrust &gt; ownertrust </code></pre> <p>If your environment variable <code>GPGKEY</code> isn't defined in <code>.bashrc</code>, look for the line that starts something like "sec 1024D/" from <code>gpg --list-keys</code> command. The part after key type (such as <code>1024D</code> or <code>2048R</code>) is the key ID.</p> <p>Store securely the files <code>fooatbardotcom_public_key.asc</code>, <code>fooatbardotcom_private_key.asc</code>, and <code>foobaratdotcom_revoke_key.asc</code>. For example store it in a password protected archive file on a USB drive, and keep the USB drive safe.</p> <h2>Setting up your keys on a different computer</h2> <p>Copy the public and private keys to other computers.</p> <p>Import keys</p> <pre><code>gpg --import fooatbardotcom_public_key.asc gpg --import fooatbardotcom_private_key.asc </code></pre> <p>Restore trust data:</p> <pre><code>gpg --import-ownertrust XXXownertrustfile </code></pre> <h2>Adding a secondary user ID to your key</h2> <pre><code>$ gpg --edit-key $GPGKEY &lt;snip&gt; gpg&gt; adduid Real name: Foo Bar Email address: foobar@hotmail.com Comment: secondary email You selected this USER-ID: "Foo Bar (second user id) &lt;foobar@hotmail.com&gt;" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O You need a passphrase to unlock the secret key for user: "Foo Bar &lt;foobar@gmail.com&gt;" 2048-bit RSA key, ID XXXXXXXX, created 2011-06-04 pub 2048R/XXXXXXXX created: 2011-06-04 expires: never usage: SC trust: ultimate validity: ultimate sub 2048R/XXXXXXXX created: 2011-06-04 expires: never usage: E [ultimate] (1) Foo Bar &lt;foobar@gmail.com&gt; [ unknown] (2). Foo Bar (secondary email) &lt;foobar@hotmail.com&gt; gpg&gt; uid foobar@hotmail.com pub 2048R/XXXXXXXX created: 2011-06-04 expires: never usage: SC trust: ultimate validity: ultimate sub 2048R/XXXXXXXX created: 2011-06-04 expires: never usage: E [ultimate] (1) Foo Bar &lt;foobar@gmail.com&gt; [ unknown] (2). Foo Bar (secondary email) &lt;foobar@hotmail.com&gt; gpg&gt; trust ... gpg&gt; 5 ... gpg&gt; save </code></pre> <h2>Using gpg-agent in daemon mode</h2> <p>See <a href= "http://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html#Invoking-GPG_002dAGENT"> "Invoking GPG-AGENT." <em>The GNU Privacy Guard Manual</em>.</a></p> <h2>Revoke and unrevoke keys</h2> <p>If your private key is lost or compromised, your encryption is not safe. And your key pair is no longer useful for encyrpting data. You probably want to revoke the key pair in that situation:</p> <pre><code>$ gpg --import revoke.asc $ gpg --keyserver keyserver.ubuntu.com --send-key $GPGKEY </code></pre> <p>At the unlikely event where you need to unrevoke keys, follow instructions at <a href= "https://help.ubuntu.com/community/GnuPrivacyGuardHowto#Un-revoking%20a%20keypair"> Ubuntu Documentation: GnuPrivacyGuardHowto</a></p> <h2>Note on the difference and relation between <code>gnupg</code> and <code>gnupg2</code></h2> <p>On superuser.com, there's a discussion about the difference and relation between GnuPG and GnuPG2. Here is an excerpt:</p> <p>Source: http://superuser.com/questions/655246/are-gnupg-and-gnupg2-compatible-with-each-other/</p> <blockquote> <p>gpg2 is a redesigned version of gpg -- but changes are mostly on internal level. The newer version is split into multiple modules, for example there are also modules for X.509 (used by S/MIME).</p> <p>From man gpg2:</p> <p>In contrast to the standalone version gpg, which is more suited for server and embedded platforms, this version is commonly installed under the name gpg2 and more targeted to the desktop as it requires several other modules to be installed.</p> <p>gpg will stay for embedded and server usage, as it brings less dependencies and smaller binaries.</p> <p>From man gpg:</p> <p>This is the standalone version of gpg. For desktop use you should consider using gpg2.</p> <p>To directly answer your question:</p> <p>Should I install both, or just one is enough? Does it matter which one I install first matter at all?</p> <p>Just install both. They don't interfere anyway. Install gpg (if not installed anyway) for other applications that access it (like package managers, mail clients, ...), and gpg2 for "direct use" on the command line.</p> <p>If I installed both, are both compatible with each other?</p> <p>Both implement the OpenPGP protocol, so they're compatible to each other regarding data shared among them. Additionally, they're (mostly) using the same commands and options, so most of the time you could switch between them arbitrarily.</p> </blockquote> <h2>References</h2> <ul> <li><a href= "https://help.ubuntu.com/community/GnuPrivacyGuardHowto">Ubuntu Documentation: GnuPrivacyGuardHowto</a></li> <li><a href= "http://www.dewinter.com/gnupg_howto/english/GPGMiniHowto.html">GPG Mini How-To</a></li> <li><a href="http://www.gnupg.org/documentation/">GnuPG Documentation Sources</a></li> <li><a href= "http://www.gnupg.org/documentation/manuals/gnupg/"><em>The GNU Privacy Guard Manual</em></a></li> <li><a href= "http://en.wikipedia.org/wiki/Key_server_(cryptographic">Wikipedia: Key server</a>)</li> <li><a href= "https://help.ubuntu.com/community/GnuPrivacyGuardHowto#Tips%20and%20Tricks"> Ubuntu Documentation: GnuPrivaryGuardHowTo: Tips and Tricks</a></li> <li><a href="http://pgp.cs.uu.nl/">PGP pathfinder &amp; key statistics</a></li> <li><a href="http://www.madboa.com/geek/gpg-quickstart/">GPG Quick Start by Paul Heinlein</a></li> </ul>