2

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

Then

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?

Thanks

1 Answer 1

8

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
     HostName 192.168.1.100
     User root
     IdentityFile ~/.ssh/nas01.key

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

You can read more here

1
  • Yep that's worked perfectly - I was overcomplicating things. Thanks for your help! Commented Oct 3, 2019 at 14:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.