I am trying to add a remote address to a branch, but when trying to fetch, or do git ls-remote
, I get Permission denied:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
So I'm wondering how to troubleshoot this? I tried using regular command line and Git bash.
It worked when I tried a different repo and server, connecting with root user in the same way:
git remote add prod ssh://[email protected]:22/myfolder/gittest.git
The successful message is: From ssh://[email protected]:22/myfolder/gittest.git
On the problematic server the user has access and I can ssh with no problem , I specify a key at the same time:
ssh -i .ssh/mykey.pem [email protected]
When I try to add the remote to the server, I do this:
git remote add prod ssh://[email protected]:22/myfolder/gittest.git
But it needs the .pem
file , so I've specified it in .ssh/config
:
Host theserver
HostName 22.22.22.222
IdentityFile ~/.ssh/myfile.pem
Port 22
How can I verify that the .pem
file being read? If I remove the text from config
, there is no error about "missing key" or anything?
The folder exists on the server: /myfolder/gittest.git
(myfolder is at the root).
I also tried to a differemt location for the repo, moving it into a sub directory to the user. But it's the same error.
So how can I pinpoint the problem?
If it's of any use, when I check the user on the server: id myuser
I get:
uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),4(adm),20(dialout),24(cdrom),
25(floppy),27(sudo),
29(audio),30(dip),33(www-data),44(video),46(plugdev),119(netdev),120(lxd)
CodePudding user response:
You have the (mostly) correct host alias set up in your configuration. Your URL just has to reference it. So define theserver
as you are, but include the user name as well.
Host theserver
User myuser
HostName 22.22.22.222
IdentityFile ~/.ssh/myfile.pem
Port 22
Now configure git
with
git remote add prod theserver:myfolder/gittest.git
When trying to connect to theserver
, SSH will look for a Host
entry with that name. What it won't do is take ssh://[email protected]:22/myfolder/gittest.git
and look for a Host
block with the same address.
CodePudding user response:
Use IdentitiesOnly yes
in .ssh/config
like this
Host theserver
HostName 22.22.22.222
IdentityFile ~/.ssh/myfile.pem
Port 22
IdentitiesOnly yes
Otherwise default ~/.ssh/id_rsa
will be tried before