Correctly Added a New SSH Key But Still Can't Pull from Repo
Asked by David Newey:

I created a new SSH key and added it to my keys, checked that I could access the repo and got the correct response but when I try to pull from the repo, I get "authentication failed". Here is my consol session:

...

\[centos@ip-10-2-1-239 laravel\]$ eval \`ssh-agent\`  
Agent pid 137198

\[centos@ip-10-2-1-239 laravel\]$ ssh-keygen -t ed25519 -b 4096 -C "denewey@gmail.com" -f \~/.ssh/id_rsa_apr_net  
Generating public/private ed25519 key pair.  
Enter passphrase (empty for no passphrase):  
Enter same passphrase again:  
Your identification has been saved in /home/centos/.ssh/id_rsa_apr_net.  
Your public key has been saved in /home/centos/.ssh/id_rsa_apr_net.pub.  
The key fingerprint is:  
SHA256:5vXPHPZx8kBs6zmbiJf64jqscHTWXFuyHIVX+US8Auo denewey@gmail.com  
The key's randomart image is:  
+--\[ED25519 256\]--+  
\| ..++\|  
\| .....o\|  
\| . =...o\|  
\| + o O ..\|  
\| . S + + = \|  
\| . = E . o . \|  
\| . ... ..\*..\|  
\| o o ..oB.Oo\|  
\| ...++=o Ooo\|  
+----\[SHA256\]-----+  
\[centos@ip-10-2-1-239 laravel\]$ ssh-add \~/.ssh/id_rsa_apr_net  
Enter passphrase for /home/centos/.ssh/id_rsa_apr_net:  
Identity added: /home/centos/.ssh/id_rsa_apr_net (denewey@gmail.com)  
\[centos@ip-10-2-1-239 laravel\]$ less \~/.ssh/id_rsa_apr_net.pub  
\[centos@ip-10-2-1-239 laravel\]$  
\[centos@ip-10-2-1-239 laravel\]$  
\[centos@ip-10-2-1-239 laravel\]$ ssh -T git@bitbucket.org  
authenticated via ssh key.

You can use git to connect to Bitbucket. Shell access is disabled  
\[centos@ip-10-2-1-239 laravel\]$ git pull  
The requested repository either does not exist or you do not have access. If you believe this repository exists and you have access, make sure you're authenticated.  
fatal: Could not read from remote repository.

Please make sure you have the correct access rights  
and the repository exists.

...

Any idea what I might be doing wrong?


Answers:
author: Theodora Boudale
body: Hi [@David Newey](/t5/user/viewprofilepage/user-id/5194462) and welcome to the community!

The private SSH key you created may not be offered during the git pull operation.

I would suggest creating a file named **config** in your **\~/.ssh folder** and adding the following lines (if the file exists, just add the following content)

```
Host bitbucket.org
? ? ? ? AddKeysToAgent yes
? ? ? ? IdentityFile /home/centos/.ssh/id_rsa_apr_net
```

This will ensure that this specific SSH key is offered every time you clone/pull/push to a Bitbucket Cloud repo.

I would also suggest double-checking permissions: premissions should be 700 for the \~/.ssh directory, 644 for the public SSH key, and 600 for the private key.

Please feel free to let us know how it goes and if you need any further help!

Kind regards,  
Theodora

comments: author: Christian FOMEKONG
body: Please [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

Is there any problem if my .ssh folder is elsewhere than \~/?

Like in /opt/other_folder/


author: Nic Brough -Adaptavist-
body: Yes. Most programs assume ssl certificates and keys are kept in \~/.ssh. If you have put them somewhere else, you need to tell any programs where they are so that they can use them.

For example,

"ssh 192.168.0.1" does not specify any key, so it defaults to looking for \~/ssh/id_rsa

"ssh 192.168.0.1 -i /opt/other_folder/my_renamed_key_file" will take the file named as containing the key you want to use.


author: Christian FOMEKONG
body: Thank you [@Nic Brough -Adaptavist-](/t5/user/viewprofilepage/user-id/781454)

So I'm facing an issue since 4 days on our production server's.

I suddendly don't be able to perform any git command towards our bibucket remote repo.

Usually we are on https mode but suddenly it stops to work with this message : **gnutls_handshake() failed: Error in the pull function**

Then I made configuration for ssh (changing remote url, generate ssh key and add it on bitbucket remote repo configurations etc ) and when I try a command, the CLI doesn't prompt anything as response.

Please for help.


author: Nic Brough -Adaptavist-
body: This suggests that your key is invalid, or not recognised because you have not added it to Bitbucket.


author: Christian FOMEKONG
body: And what about https connection, which stopped to work suddely without any configurations. [@Nic Brough -Adaptavist-](/t5/user/viewprofilepage/user-id/781454)


author: Nic Brough -Adaptavist-
body: It's the same answer - your key is not valid, or not recognised.


author: Graham Twine
body: I am assuming you have access to the repository as Nic has mentioned above.

Add the contents of your public key to bitbucket as mentioned [here](https://confluence.atlassian.com/bitbucketserver/ssh-user-keys-for-personal-use-776639793.html). Check the application Cloud / DC version etc. I think you are using cloud by the ssh command used.

You can find it here, but I think you have copied it?

```
 /home/centos/.ssh/id_rsa_apr_net.pub
```

Is this a git repository you are in already?  
Can you use interactive authentication to clone the repository?

e.g.

```
git clone https://user@bitbucket.org/PKEY/repo-name.git
```

If the above works and as already mentioned, you have added your public key to bitbucket

```
git clone ssh://git@bitbucket.org/PKEY/repo-name.git
```


author: Nic Brough -Adaptavist-
body: Welcome to the Atlassian Community!

Have you added the key to Bitbucket? And does the account have access to the repositories?


Tags: bitbucket-cloud

cloud

ssh-key