When I'am connecting to ssh with gnome-terminal application opens gnome-keyring dialog, so I am entering password only once per session and I can reconnect to same ssh more than once without asking the password.

But this doesn't work in xterm. Maybe someone can help to make this work?

  • 1
    How exactly do you start gnome-terminal and xterm? Did you do any setup to be able to use gnome-keyring? What OS/distribution are you running? Apr 15, 2011 at 19:33

3 Answers 3


Are you running xterm from inside your Gnome session as well?

Try this in Gnome Terminal:


Then try the same in xterm.

It should print something like


in both.

I'm guessing it doesn't print something like that in xterm.

If it's empty, something is clearing it (or not setting it).

If looks more like


then you are also running ssh-agent somewhere, which will get confusing.

Here's what I'd try:

Run echo $0 in both. Does one have - at the start and the other not?

If so, you are probably running ssh-agent in login shells, but not non-login shells. Have a look in your ~/.bashrc or ~/.bash_profile or equivalent scripts and fix the problem.

Or change whether xterm is started as a login shell:

  1. using xterm*loginShell: true or xterm*loginShell: false in your ~/.Xdefaults or ~/.xresources?
  2. by running xterm -ls or xterm (without -ls)

Copy the setting you have for Gnome Terminal under Profile Preferences->Title and Command->Run command as a login shell.

If that fails, try adding echo statements in your startup files. You'll need to redirect the output to a log file using echo $SSH_AUTH_SOCK >> ~/ssh-debug.log or similar.

Then log out and back in, and have a look at your ~/ssh-debug.log.

Then run Gnome Terminal and look at it again.

Then run xterm and look and look at it again.

Look for differences.

Have a look at /etc/pam.d/gdm and System->Preferences->Startup Applications. Do you have any other ssh-agent configuration anywhere in /etc/pam.d?

Have a look /etc/X11/Xsession and the scripts that it calls.

  • When I echo $SSH_AUTH_SOCK in xterm I've got: /tmp/ssh-mIDzpMya1902/agent.1902. In gnome-terminal: /tmp/keyring-F5L0Fh/ssh. If I set export SSH_AUTH_SOCK=/tmp/keyring-F5L0Fh/ssh then xterm works with gnome-keyring. What should I do to set this value in xterm (this value should be the same as in gnome terminal, but every new terminal window this value changes)?
    – user6621
    Apr 15, 2011 at 13:22
  • As I have explained, you will need to look at your own setup, because it is different from mine. Look at your ~/.bashrc and ~/.bash_profile to start with and see if they contain ssh-agent. If not, look at /etc/pam.d and /etc/X11/Xsession.
    – Mikel
    Apr 15, 2011 at 22:21

You can also have a look at the workaround given at Red Hat Bugzilla - Bug 713955 - SSH_AUTH_SOCK environment variable not present in terminals launched via keyboard shortcut by adding this to your ~/.bashrc:

#GPG and SSH agent not exported when running terminal by shortcut
if [ -z "$GPG_AGENT_INFO" -a -z "$SSH_AUTH_SOCK" -a -n "$GNOME_KEYRING_CONTROL" ] ; then
        #derive GPG and SSH agent info from GNOME_KEYRING_CONTROL
        export GPG_AGENT_INFO="$GNOME_KEYRING_CONTROL/gpg:0:1"

In my case (Centos 6 with gnome 2.28), the GNOME_KEYRING_CONTROL variable does not exist (but GNOME_KEYRING_SOCKET does), and the gnome keyring "seahorse" does not seem to provide GPG_AGENT_INFO.

So I ended up with this version (also placed in ~/.bashrc):

set_keyring_agent() {
# SSH agent not exported when running terminal by shortcut
# see https://bugzilla.redhat.com/show_bug.cgi?id=713955#c4
# and http://unix.stackexchange.com/questions/11355/its-possible-to-make-xterm-and-gnome-keyring-work-together
if [[ -n "${GNOME_KEYRING_SOCKET}" && -z "${SSH_AUTH_SOCK}" ]] ; then
  #derive SSH agent info from GNOME_KEYRING_SOCKET
  local ssh_auth_socket="${GNOME_KEYRING_SOCKET}.ssh"
  if [[ -S "${ssh_auth_socket}" ]] ; then
    export SSH_AUTH_SOCK="${ssh_auth_socket}"


While I didn't figure out what magic makes gnome-terminal get the correct SSH_AUTH_SOCK from gnome-keyring-daemon, I found a workaround to set the correct value in XTerm (or other terminals). Add the following to your .bashrc:

SSH_AUTH_SOCK=`netstat -xl | grep -o '/tmp/keyring-.*/ssh$'`
[ -z "$SSH_AUTH_SOCK" ] || export SSH_AUTH_SOCK

What this does: it looks for a local listening socket which has a name matching the pattern "/tmp/keyring-*/ssh", and sets the value of SSH_AUTH_SOCK to that, if it's present.

Source: http://ubuntuforums.org/showthread.php?p=10786874#post10786874

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy