2

I want to use ssh passwordless-login using authentication-key-pairs.

I added

eval `ssh-agent -s`
ssh-add ~/.ssh/my_p_key

to ~/.profile. This doesn't work. If I use the ~/.bashrc it works fine.

Why do I have to set this every time I call a bash instead of every time the user logges in. I could not find any explanation.

Is there no better way to configure this?

Yaerox
  • 608
  • 2
  • 11
  • 27

3 Answers3

3

The answer below solved my problem and for me it looks like a very legit solution.

Add private key permanently with ssh-add on Ubuntu

Community
  • 1
  • 1
Yaerox
  • 608
  • 2
  • 11
  • 27
0

The

eval `ssh-agent -s` 

sets the environment of the process. If you are using a window manager e.g. on a linux machine then the window manager will likely have a possibility to run a program like e.g. your ssh-agent on startup and passing the environment down to all processes started there, so all your terminal windows/tabs will allow you a passwordless login. The exact location, configuration and behaviour depends on the desktop/wm used.

If you are on a non-window-system, then you might look at the output of the ssh-agent call and paste that into all shells you open, however that may be as complicated as entering your password. The output will likely set something like

SSH_AGENT_PID=4041
SSH_AUTH_SOCK=/tmp/ssh-WZANnlaFiaBt/agent.3966

and you can access pw-less in all places where you set these

Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26
  • You can also check for a running ssh-agent and set the variables based on its PID automatically. – choroba Jun 29 '16 at 15:00
0

Just adding "IdentityFile ~/.ssh/config" to my .ssh/config did not work for me. I had to also add "AddKeysToAgent yes" to that file.

I think this extra line is necessary because gnome-Keyring loads my key but it has a bug that prevents it from being forwarded to the machine I ssh into.

Edit: After upgrading to Ubuntu 20.04, new terminals that I started could not access the ssh-agent. I had to add eval (ssh-agent -c) &>/dev/null to my ~/.config/fish/config.fish file.

akindofyoga
  • 970
  • 1
  • 9
  • 16