When the terminal is not enough
Sometimes I'm surprised by utilities that run fine in a terminal window on a graphical desktop but fail to do so in a remote SSH connection. Unfortunately, this seems to be a side-effect of software on desktop Linux getting more tightly integrated. These days, it's more and more common to see a command-line tool pop up a graphical dialog. It looks fancy, and there might be security benefits in the case of passphrase entries, but it also means that often the remote use case with no access to the local desktop gets overlooked.
The GNOME keyring management is one offender I bump against the most. It tries to handle all entry of sensitive credentials, like passwords and PINs on a system and integrates with the SSH and GPG agents. I remember that it used to interfere with private SSH key passphrase entry when jumping from one SSH connection to another, but that seems to be fixed in Debian Stretch.
On the other hand, running GPG in a SSH session by default still doesn't work (this might also pop up when, for example, signing git tags):
$ gpg -s gpg_test gpg: using "0A822E7A" as default secret key for signing gpg: signing failed: Operation cancelled gpg: signing failed: Operation cancelled
This happens when that same user is also logged in to the graphical desktop, but the graphical session is locked. I'm not sure exactly what happens in the background, but something somewhere seems to cancel the passphrase entry request.
The solution is to set the GPG agent to use the text-based pin entry tool. Install the pinentry-tty package and put the following into ~/.gnupg/gpg-agent.conf
:
pinentry-program /usr/bin/pinentry-tty
After this, the passphrase can be entered through the SSH session:
$ gpg -s gpg_test gpg: using "0A822E7A" as default secret key for signing Please enter the passphrase to unlock the OpenPGP secret key: "Tomaž Šolc (Avian) <tomaz.solc@tablix.org>" 4096-bit RSA key, ID 059A0D2C0A822E7A, created 2013-01-13. Passphrase:
Update: Note however that with this change in place graphical programs that run GPG without a terminal, such as Thunderbird's Enigmail extension, will not work.
Another offender are PulseAudio- and systemd-related tools. For example, inspecting the state of the sound system over SSH fails with:
$ pactl list Connection failure: Connection refused pa_context_connect() failed: Connection refused
Here, the error message is a bit misleading. The problem is that the XDG environment variables aren't set up properly. Specifically for PulseAudio, the XDG_RUNTIME_DIR should be set to something like /run/user/1000
.
This environment is usually set by pam_systemd.so PAM module. However, some overzealous system administrators disable the use of PAM for SSH connections, so it might not be set in an SSH session. To have these variables set up automatically, you should have the following in your /etc/ssh/sshd_config
:
UsePAM yes