ssh-add OpenSSHPrivateKey at login

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

after my last posting here ("ssh over proxy") i will try now the next
one :-)

OK my ssh going now (with proxy too).

I use to authenticate my login to another computers RSA krypt. with
OpenSSHPrivateKey and PublicKey. I think this is the best.

BTW to manage these kind of login i use a bash shell and the ssh-agent
and ssh-add commands.

1. i open a shell and type into this shell "exec ssh-agent bash"
2. now the command "ssh-add ~.ssh/OpenSSHPrivateKey"
3. now i must type in my OpenSSHPrivateKey password (unpractical)

This is great but it is little bit unpractical evrey time to type in my
password for load my PrivateKey. Particularly these services i have only
at this shell and not at all my shells ...

My question is now. It takes a possibillty this key to load at the logon
at my computer with my computer logon password. e.g. start these
processes at the beginning (at booting my computer or something like
this - i start my computer; do login; the ssh-agent is running now and
my PrivateKey is loaded without an extra password).

Best regards

Re: ssh-add OpenSSHPrivateKey at login

Quoted text here. Click to load it

You don't have to set a password for a private key. Just make sure you don't
lose it.

Re: ssh-add OpenSSHPrivateKey at login

Quoted text here. Click to load it

Basically, you just need to to store the details of the running agent
and import the environment variables into each shell.  Note that if
someone breaks into your machine they will be able to use the running
agent to authenticate sessions.

Some will advise removing the passphrase from the key.  This is much less
secure.  See:

Anyway, you can use something like this.  Be aware that you need to
"source" this (ie run it with ". scriptname") or put it into a file
automatically sourced (eg .profile).

# Check if agent is running
if ps -eaf | awk '$1=="'$LOGNAME'"' | egrep '[s]sh-agent' >/dev/null
        # Agent is running, get details
        echo agent is running
        if [ -f $HOME/.ssh/running-agent.`hostname` ]
                . $HOME/.ssh/running-agent.`hostname`
        echo Starting ssh-agent.
        ssh-agent -s >$HOME/.ssh/running-agent.`hostname`
        . $HOME/.ssh/running-agent.`hostname`

There's probably better ways to do this with X-based session managers
but I don't know any off the top of my head.

Darren Tucker (dtucker at
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.

Re: ssh-add OpenSSHPrivateKey at login

divejbba wrote:

Quoted text here. Click to load it

What I have in ~/.bash.profile

if [ -f ~/tmp/SSH_AUTH_SOCKNAME ]

if [  -z "$SSH_AUTH_SOCK" -o ! -e "$SSH_AUTH_SOCK" ]
    ssh-agent | tee ~/tmp/SSH_AUTH_SOCKNAME

In cron I kill the ssh-agent each evening and the result is I have to type
the passphrase once per day.

Elvis Notargiacomo        

Site Timeline