简体   繁体   中英

I need to re-run eval(ssh-agent) and ssh-add on every boot

I'm wondering if I could get some help. I recently reinstalled my OS and I'm running into a strange issue that I've never run into before. I'm following the Github steps to add ssh agent

Basically, every time I log in I need to run

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_personal

when I reboot my computer.

When I try to run git clone X I'm getting

Cloning into 'X'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

but after I run the above 2 commands, I cna clone just fine

Note: issue is also with Gitlab. Sorry, I should have been explicit

It sounds like you're running on Linux, and your login is probably "bash".

If so, I would consider adding these two lines to the bottom of your ~/.bashrc login file:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_personal

You might also consider trying this:

Adding my own answer:

I think the issue was that when I made the first key, I changed the name from the default. Ie I changed from

~/.ssh/id_id_edX -> ~/.ssh/id_personal

After removing the key and regenerating things it all worked out. Why? IDK

Try this, I found it somewhere online. Add this to your ~/.bashrc file

    if [ -z "$SSH_AUTH_SOCK" ] ; then
    eval `ssh-agent -s`
    ssh-add ~/.ssh/<NAME OF YOUR PRIVATE KEY>
    fi

This assumes your private key is located under .ssh. Otherwise, use the adequate path

I saw that you mentioned using zsh for your shell. You can add ssh-agent to your plugins and it'll handle it for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM