Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start ssh-agent on login [closed]

I have a site as a remote Git repo pulling from Bitbucket.com using an SSH alias. I can manually start the ssh-agent on my server but I have to do this every time I login via SSH.

I manually start the ssh-agent:

eval ssh-agent $SHELL 

Then I add the agent:

ssh-add ~/.ssh/bitbucket_id 

Then it shows up when I do:

ssh-add -l 

And I'm good to go. Is there any way to automate this process so I don't have to do it every time I login? The server is running RedHat 6.2 (Santiago).

like image 319
Pathsofdesign Avatar asked Sep 18 '13 18:09

Pathsofdesign


People also ask

Does ssh-agent need to be running?

On most Linux systems, ssh-agent is automatically configured and run at login, and no additional actions are required to use it. However, an SSH key must still be created for the user. The ssh-agent command outputs commands to set certain environment variables in the shell.

How do I automatically add ssh keys?

Adding a key to your ssh-agent on LINUX/OSX On OSX this is automatic, on Linux you may need to do it manually or with a script. To load your key into the ssh-agent simply run ssh-add ~/. ssh/<keyname>. If you password protected your private key you will be asked to enter the password.

How do I stop ssh asking for passphrase?

just running the command "ssh-add" and enter the password once, command line will not prompt you for the password again. You don't need any arguments; just running ssh-add will automatically add ~/.


1 Answers

Please go through this article. You may find this very useful:

https://web.archive.org/web/20210506080335/https://mah.everybody.org/docs/ssh

Just in case the above link vanishes some day, I am capturing the main piece of the solution below:

This solution from Joseph M. Reagle by way of Daniel Starin:

Add this following to your .bash_profile

SSH_ENV="$HOME/.ssh/agent-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 

This version is especially nice since it will see if you've already started ssh-agent and, if it can't find it, will start it up and store the settings so that they'll be usable the next time you start up a shell.

like image 195
Litmus Avatar answered Sep 21 '22 12:09

Litmus