Forums

Save my ssh passphrase

Hi !

For my github connection, I generated a ssh key, in ~/.ssh/id_rsa.pub When I run a ssh command, the console ask me the passphrase of the key. This is normal, but I do not want to type it all the time!

I have created a ssh-agent, but I have to do it again every time I log on to the console.

Is there any way to save my passphrase or am I doomed to type it every time I want to connect to my git repo? :p

Thank you in advance and sorry for my bad english, I'm french!

Hi there,

I've been experimenting with this myself. I've got a script like this in my bashrc:

SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s -t 12h"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ];
then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

and then you can use ssh-add to save your key for that session.

it just about works, although i suspect it ends up starting multiple ssh-agents on the same server. there's probably a way of making it more clever... maybe by writing the auth_sock and agent_pid to a file in /tmp? and then some sort of check to see if it's really running, and restart it if necessary?

Yep, I tested this, and it works, thanks !

I added just the ssh-add like this :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s -t 3h"
SSHADD=/usr/bin/ssh-add
SSHADDARGS="-t 3h .ssh/id_rsa"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ];
then
    eval `$SSHAGENT $SSHAGENTARGS`
    eval `$SSHADD $SSHADDARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

I tape the passphrase when I log on, and I'm quiet for 3h.

1
2
3
4
5
6
Kmaschta@ssh.pythonanywhere.com's password: 
Agent pid XXXXX
Enter passphrase for .ssh/id_rsa: 
Identity added: .ssh/id_rsa (.ssh/id_rsa)
Lifetime set to 10800 seconds
~ $

I did not need more, I just connects to tinker. Thanks !

Cool. Thanks for sharing that.