How can I avoid always having to use `eval 'ssh-agent -s'`

6,963

As @Jakuje said, using Forward Agent and using a key on your local, secure machine is better.

However, if you need to do what you say, use a tool such as keychain (github.com/funtoo/keychain) or ssh-find-agent (github.com/wwalker/ssh-find-agent ( I wrote the latter, and many still use it, but I have since switched to using the former ). Both of these tools look for running gpg or ssh agents and connectyour environment up to them for you.

Share:
6,963

Related videos on Youtube

horatio1701d
Author by

horatio1701d

Updated on September 18, 2022

Comments

  • horatio1701d
    horatio1701d almost 2 years

    I can't figure out why everytime I ssh back into my server I always have to start my ssh agent with the command eval 'ssh-agent -s' followed by ssh-add <my_key.pem> in order to successfully ssh from my server. I have placed this in my .bashrc but obviously I'm missing something and don't want to always have to initialize that each time I log in.

    • YoloTats.com
      YoloTats.com over 8 years
      Maybe a ssh-reagent script may help you?
    • YoloTats.com
      YoloTats.com over 8 years
      You need to call the ssh-reagent() function (the gist only define it). There need also already a ssh-agent running.
    • horatio1701d
      horatio1701d over 8 years
      Thanks again for this. I called it from my bashrc and seems to work now but i noticed a ton of ssh-agent processes running after that. Is there a way to just re-use same process?
    • YoloTats.com
      YoloTats.com over 8 years
      Are you sure, that the the ssh-agent did not run previously? The ssh-reagent script does not start new ones.
  • Julian Cienfuegos
    Julian Cienfuegos almost 7 years
    I wonder what I did.... I had this issue when I set up ssh for my github account. Then I set up ssh for my digital ocean droplet and after doing ssh-copy-id, ssh-add, and then connecting to my webserver, the issue went away. I just restarted my computer and miraculously I don't have to start the agent any more. WEIRD
  • clay
    clay over 3 years
    Not my choice cause I have hundreds of repos and do not put them to my ssh config ~/.ssh/config
  • clay
    clay over 3 years
    Not my choice cause I have hundreds of repos and do not put them to my ssh config ~/.ssh/config