flyingL123
flyingL123

Reputation: 8076

Adding key to ssh agent when shell is opened

Why isn't this code working in my .bash_profile?

echo $SSH_AUTH_SOCK
if [ -z "$SSH_AUTH_SOCK" ]; then
        ssh-add
fi

My identity is not getting added when shell is opened. The variable $SSH_AUTH_SOCK is being echoed when the shell opens:

/private/tmp/com.apple.launchd.UKHCb6uhHB/Listeners

So if the variable is defined, why isn't the ssh-add statement being evaluated?

If I run ssh-add manually from the command line, or place it on it's own separate line of my .bash_profile, it successfully runs and adds my identity to the ssh agent.

Additionally, making thing simpler and just trying to echo a value doesn't work, for example, I do not see test being echoed after placing this in the file:

echo $SSH_AUTH_SOCK
if [ -z "$SSH_AUTH_SOCK" ]; then
    echo test
fi

Upvotes: 0

Views: 108

Answers (1)

flyingL123
flyingL123

Reputation: 8076

Whoops, I was using the wrong operator. Should be -n, not -z.

Upvotes: 1

Related Questions