I have a Git repo that is authenticated with an SSH key - the key is not the standard id_rsa.

I can run:

eval $(ssh-agent -s)
ssh-add /home/forge/.ssh/otherkey


git pull origin master

This is working.

The server needs to do a git pull on boot.

So I have code in rc.local that pull the repo it's working only when the key is default id_rsa but not when the key is different.

If I add it in bashrc then it does add the key and work when I log in, but not immediately from boot.

How can I add an alternative SSH key than id_rsa for git to use, that can be instantiated before my git pull command in rc.local?



You can add ssh key file using ssh config.

Here is default for all users /etc/ssh/ssh_config
Here is for current user ~/.ssh/config

Example of current user ssh config per host:

## Home nas server ##
Host nas01
     User root
     IdentityFile ~/.ssh/nas01.key

## Login AWS Cloud ##
Host aws.apache
     User wwwdata
     IdentityFile ~/.ssh/aws.apache.key

You can read more here

  • Yep that's worked perfectly - I was overcomplicating things. Thanks for your help! – samiles Oct 3 '19 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.