How do I add my ssh key to my keyring?

Hello,

I just finished setting up an ssh key so that I wouldn't have to enter in my username / password when pushing to GitHub each time. However, I still need to enter in the password I assigned my ssh key when first making this. I'd like to keep my ssh key encrypted, but also not have to type in the password whenever I push.

I've heard that I need to add my ssh key to my keyring, but I don't know what that is and how I would do it. It looks like I have three different keyrings installed - archlinux-keyring, gnome-keyring, and manjaro-keyring. Which of these would I use, and how would I use it?

Thanks - k

You need to copy the key to the client machine.

Lets say you have created a key for your Desktop PC and you want to login from your laptop to your Desktop PC. Then you need to copy the key from the Desktop PC to your laptop. The best way to do this is ssh-copy-id. You should run ssh-copy-id on the Desktop PC as the user who wants to login.

1 Like

How is any of this related to setting up ssh for Github? :confused:

I think you mean add it to the ssh authentication agent. in that case it would be ssh-add /path/to/private_key and/or you setup your ssh config properly.

It's none of the above options.

You didn't need to give the ssh key you generated a password. If you did do it again following the github steps without one.

Hi! :vulcan_salute:
This is a possible solution if you use the terminal for Git.
The SSH agent will load in a terminal and will ask for the password the first time (once) for that process. It does not use any keyring.
Just add the following to your .bashrc (source):

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

I usually also put the following in my ssh config ($HOME/.ssh/config) for each host:

Host github
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/NAME_OF_PRIVATE_KEY
User git

Note the line: AddKeysToAgent yes;
"Specifies whether keys should be automatically added to a running ssh-agent" (from man ssh_config).

Hope this works!

1 Like

Whoops. I missed the github piece.

If I don't set a password, my ssh key is stored in plaintext :confused:

Alright! I'm trying that. Two things though - I didn't have a config file in ~/.ssh before, and I just added the block of code to the top of the .bashrc file. I hope those are both fine.

Also, after signing in (it opened a prompt after opening my terminal), I'm unable to push / pull (but it doesn't ask for my username!) This may be the network I'm on at the moment, I'll try it again on another one.

EDIT: Works perfectly!

1 Like

The point of a key-pair is the private key should never be leaving your computer and the public key is given to github. So what you just said above is completely irrelevant. As long as no one else has the private key it doesn't matter.

@klorax

So your solution works perfectly, but I have to enter in my SSH key password after a reboot. Is there a way to not need to do that?

There probably is, but it is beyond my knowledge. My guess is that you would have to autostart the SSH agent and use some keyring (i.e., DE specific solution) to give it the password while logging in (and also unlocking the keyring).

Take a look at keychain.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by