'Configure Git to use a .pem key from a specific location
Whenever I try to do a 'git pull origin master' I get (It is NOT Github):
Permission denied (publickey).
I am able to SSH into my AWS EC2 Linux sever, which has the bare repository, which I'm trying to pull from when I get the aforementioned permission error.
I have indeed copied the public key to that server, because I can login successfully via ssh, but only by doing a:
ssh -i /location/of/pemkey/mykey.pem [email protected]
I need to configure Git to use my '.pem' key. How do I accomplish setting up Git to utilize my '.pem' key?
Solution 1:[1]
From the git(1) man page:
GIT_SSH
If this environment variable is set then git fetch and git push
will use this command instead of ssh when they need to connect to a
remote system. The $GIT_SSH command will be given exactly two or
four arguments: the username@host (or just host) from the URL and
the shell command to execute on that remote system, optionally
preceded by -p (literally) and the port from the URL when it
specifies something other than the default SSH port.
To pass options to the program that you want to list in GIT_SSH you
will need to wrap the program and options into a shell script, then
set GIT_SSH to refer to the shell script.
Usually it is easier to configure any desired options through your
personal .ssh/config file. Please consult your ssh documentation
for further details.
In my personal experience, the one-time cost of adding host settings in .ssh/config has made a big difference, even for hosts where only the username is different.
Solution 2:[2]
I got this from here, but it is not the main answer. The instructions listed here were more useful to me.
Adjust your ~/.ssh/config and add:
Host example
Hostname example.com
User myuser
IdentityFile ~/.ssh/other_id_rsa
Now use the ssh host alias as your repository:
$ git remote add origin example:repository.git
$ git pull origin master
And it should use the other_id_rsa key!
Solution 3:[3]
1. touch ~/.ssh/config
2. chmod 644 ~/.ssh/config
3. vim ~/.ssh/config
#write next codeline
host ec2-ip.eu-west-1.compute.amazonaws.com
IdentityFile ~/Documents/ec2-user.pem
git clone [email protected]:/home/git/my-repo.git
Solution 4:[4]
We can use git config core.sshCommand from git version 2.10.0.
-c option can change config temporally.
Command example for cloning.
git -c core.sshCommand="ssh -i some.pem -F /dev/null" clone ...
Reference: https://qiita.com/sonots/items/826b90b085f294f93acf
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | o11c |
| Solution 2 | Community |
| Solution 3 | dmitri |
| Solution 4 | asukiaaa |
