Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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? –  Gilles Apr 15 '11 at 19:33
add comment

migrated from stackoverflow.com Apr 15 '11 at 2:16

This question came from our site for professional and enthusiast programmers.

2 Answers

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

Try this in Gnome Terminal:

echo $SSH_AUTH_SOCK

Then try the same in xterm.

It should print something like

/tmp/keyring-abc123/ssh

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

/tmp/ssh-defgh67890/agent

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.

share|improve this answer
    
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 '11 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 '11 at 22:21
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.