{"id":413,"date":"2009-07-01T22:36:12","date_gmt":"2009-07-01T20:36:12","guid":{"rendered":"http:\/\/raftaman.net\/?p=413"},"modified":"2021-05-15T11:46:41","modified_gmt":"2021-05-15T09:46:41","slug":"automating-gnupg","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=413","title":{"rendered":"Automating GnuPG"},"content":{"rendered":"<p>If you want to use GnuPG in a script and don&#8217;t want to be prompted for the passphrase, put the passphrase in a file called <code>passphrase.txt<\/code> and use this to encrypt: <\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\ngpg --passphrase-fd 3 -c 3&lt; passphrase.txt &lt; filename &gt; filename.gpg\r\n<\/pre>\n<p>Of course, you can also use echo to specify your passphrase<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\ngpg --passphrase-fd 3 -c 3&lt; &lt;(echo &quot;secret&quot;) &lt; filename &gt; filename.gpg\r\n<\/pre>\n<p>or you can pipe a tarball into gpg<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\ntar -cf - dir\/ | gpg --passphrase-fd 3 -c 3&lt; &lt;(echo &quot;pass&quot;) &gt; backup.tar.gpg\r\n<\/pre>\n<p>or even send a gpg encrypted tarball via e-mail<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\r\ntar c dir\/ | gpg --force-mdc -ac -o - --passphrase-fd 3 -c 3&lt; &lt;(echo &quot;pass&quot;) | mail user@domain.tld\r\n<\/pre>\n<p>Note that you have to use the <code>--batch<\/code> flag if you want to run gpg from a cron script. (Otherwise gpg tries to read from \/dev\/tty that doesn&#8217;t exist for cron jobs)<A NAME=\"fn001t\" HREF=\"#fn001f\"><SUP>1<\/SUP><\/A>.<\/p>\n<p>More GnuPG hacks can be found here: <a href=\"http:\/\/www.linuxjournal.com\/article\/8732\">http:\/\/www.linuxjournal.com\/article\/8732<\/a><\/p>\n<p><!-- fn001 begin --><br \/>\n<P><br \/>\n<A NAME=\"fn001f\" HREF=\"#fn001t\">[1] <\/A><a href=\"http:\/\/stackoverflow.com\/questions\/39867\/how-to-run-gpg-from-a-script-run-by-cron\">http:\/\/stackoverflow.com\/questions\/39867\/how-to-run-gpg-from-a-script-run-by-cron<\/a><br \/>\n<\/P><br \/>\n<!-- fn001 end --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to use GnuPG in a script and don&#8217;t want to be prompted for the passphrase, put the passphrase in a file called passphrase.txt and use this to encrypt: gpg &#8211;passphrase-fd 3 -c 3&lt; passphrase.txt &lt; filename &gt; filename.gpg Of course, you can also use echo to specify your passphrase gpg &#8211;passphrase-fd 3 -c 3&lt; &lt;(echo &quot;secret&quot;) &lt;&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=413\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[28],"class_list":["post-413","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bash"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=413"}],"version-history":[{"count":7,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":699,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/413\/revisions\/699"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}