{"id":350,"date":"2011-08-20T23:08:05","date_gmt":"2011-08-20T21:08:05","guid":{"rendered":"http:\/\/tronche.com\/blog\/less-technical\/uncategorized\/2011\/08\/solved-gpg-agent-or-pinentry-ssh-or-su-not-working-on-linux-unix\/"},"modified":"2019-04-13T11:52:01","modified_gmt":"2019-04-13T09:52:01","slug":"solved-gpg-agent-or-pinentry-ssh-or-su-not-working-on-linux-unix","status":"publish","type":"post","link":"https:\/\/tronche.com\/blog\/2011\/08\/solved-gpg-agent-or-pinentry-ssh-or-su-not-working-on-linux-unix\/","title":{"rendered":"(solved) gpg-agent (or pinentry) + ssh (or su) not working on Linux \/ Unix"},"content":{"rendered":"\n<p>The case: you connect to a remote computer with &#8221;ssh&#8221;, or may be you just do &#8221;su&#8221; to become another unix user, then start something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpg-agent --daemon \/bin\/bash<\/code><\/pre>\n\n\n\n<p>or may be you worked hard so &#8221;gpg-agent&#8221; is launched from your &#8221;.profile&#8221; or something like that.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Then, you try to decrypt a file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpg -d my-file.gpg<\/code><\/pre>\n\n\n\n<p>and you expect &#8221;gpg&#8221; to enter into some dialog to ask you the passphrase. Furthermore, you expect that you won&#8217;t have to enter the passphrase again if you decrypt the same file once more a few minutes from now. And at least, if &#8221;gpg-agent&#8221; can&#8217;t remember the passphrase, you might expect it to fall back on some mechanism to ask you the passphrase.<\/p>\n\n\n\n<p>But none of all these happen. Instead you have no opportunity of dialog (what a stress !) and you got, among other things:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpg: cancelled by user<\/code><\/pre>\n\n\n\n<p>and even<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpg: public key decryption failed: bad passphrase\ngpg: decryption failed: secret key not available<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">What went wrong ?<\/h2>\n\n\n\n<p>&#8221;pinentry&#8221; or the corresponding PIN entry program is installed and found by &#8221;gpg-agent&#8221;, otherwise you would have an error like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gpg: problem with the agent - disabling agent useand a fall back on ''gpg'' internal input passphrase.<\/code><\/pre>\n\n\n\n<p>What I suspect very much, at least what I did, is that you performed an &#8221;su&#8221; since you logged in with &#8221;ssh&#8221;. Looking at the tty:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tronche@dev1:~$ ls -l `tty`crw------- 1 root tty 136, 2 2011-08-20 20:52 \/dev\/pts\/2<\/code><\/pre>\n\n\n<p>root is owning my tty (I logged in I as root. Yes, I know), and I&#8217;m user tronche.<\/p>\n<p>The point is that &#8221;pinentry&#8221; gets the tty name from &#8221;gpg-agent&#8221;. Then, &#8221;&#8217;pinentry opens it read \/ write to perform its dialog&#8221;&#8217;. If you don&#8217;t own the tty, it fails, and rightly so. For example, you logged in as root, so root owns the tty, then you &#8221;su&#8221;-ed as a regular user, the one executing gpg-agent and thus &#8221;pinentry&#8221;, and this one can&#8217;t open the tty to run the PIN entry dialog.<\/p>\n<p>Side note: the documentation states that the shell environment variable &#8221;GPG_TTY&#8221; should be set, but on my Ubuntu 10, &#8221;gpg-agent&#8221; figures very well by itself what the tty is, so you don&#8217;t really need that.<\/p>\n\n\n<h2 class=\"wp-block-heading\">What solutions ?<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Don&#8217;t do &#8221;su&#8221;. Log in as the user running gpg-agent. Obvious.<\/li><li>If, for some reason, you log in as root and then change to another user, you can (as root) &#8221;chown&#8221; <code>tty<\/code>, that&#8217;ll do the trick.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>The case: you connect to a remote computer with &#8221;ssh&#8221;, or may be you just do &#8221;su&#8221; to become another unix user, then start something <a class=\"mh-excerpt-more\" href=\"https:\/\/tronche.com\/blog\/2011\/08\/solved-gpg-agent-or-pinentry-ssh-or-su-not-working-on-linux-unix\/\" title=\"(solved) gpg-agent (or pinentry) + ssh (or su) not working on Linux \/ Unix\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247],"tags":[220,214,216,212,218],"class_list":["post-350","post","type-post","status-publish","format-standard","hentry","category-hack","tag-gpg","tag-gpg-agent","tag-pinentry","tag-ssh","tag-su"],"_links":{"self":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/comments?post=350"}],"version-history":[{"count":2,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/350\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/posts\/350\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/media?parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/categories?post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tronche.com\/blog\/wp-json\/wp\/v2\/tags?post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}