4

I want to perform git clone from bitbucket.org

git clone git@bitbucket.org:mascai/regru_junjob.git

Received error:

Cloning into 'regru_junjob'... Warning: Permanently added the RSA host key for IP address '2406:da00:ff00::34cc:ea4a' to the list of known hosts.

Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

I add pub and private keys to my server:

~/.ssh# ls
authorized_keys  id_rsa.pub  known_hosts  reg_jj  reg_jj.pub

Added pub key to the bitbucket.org https://bitbucket.org/mascai/regru_junjob/admin/access-keys/

What is the reason of the error?

May be usefull

~# ls -la ~/.ssh/
total 28
drwx------ 2 root root 4096 ноя 13 15:26 .
drwx------ 4 root root 4096 ноя 13 15:26 ..
-rw------- 1 root root  782 ноя 13 14:26 authorized_keys
-rw-r--r-- 1 root root  381 ноя 13 15:25 id_rsa.pub
-rw-r--r-- 1 root root 3978 ноя 13 15:35 known_hosts
-rw-r--r-- 1 root root 1679 ноя 13 15:26 reg_jj
-rw-r--r-- 1 root root  391 ноя 13 14:54 reg_jj.pub
alcoder
  • 437
  • 4
  • 21
  • 1
    Did you set wrong file permissions for `~/.ssh/`? Let us see the result of `ls -la ~/.ssh/`, if you feel free to share it. – ne3suszr Nov 13 '19 at 12:51
  • Have you used the Key "id_rsa.pub"? That key is used for default auth. – René Höhle Nov 13 '19 at 12:57
  • Added id_rsa.pub but received error again. Are .ssh permissions OK? – alcoder Nov 13 '19 at 13:01
  • In case if you have multiple ssh keys, you need to setup them in this way - https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/. Read it carefully, do setup, and do not forget to change git clone address according to aliases in config file. – kosist Nov 13 '19 at 14:09
  • 2
    [`ssh -Tv git@bitbucket.org`](https://stackoverflow.com/a/34894219/7976758) – phd Nov 13 '19 at 14:18
  • Your permissions are incorrect on `reg_jj` - while 0644 is fine for the .pub files, the private key (the one without the `.pub`) needs to be set to 0600. You should also check that your SSH client is using the appropriate key, but @phd's answer should cover that. – Jim Redmond Nov 13 '19 at 20:36

2 Answers2

2

Using the command ssh -Tv git@bitbucket.org suggested by @phd, I was able to figure out the issue. It was indeed, a permissions issue

Permissions 0664 for '/home/ubuntu/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
0

ssh-keygen -t rsa "To generate the SSH"

Next it will ask for the folder to create the SSH(you can press enter to create it in default folder )

press enter to confirm the folder

now you have generated the SSH Successfully

please type below command the copy the Generated SSH

cat ~/.ssh/id_rsa.pub

now you can open your BitBucket Account and personal settings -> Security -> SSH then paste the SSH key you copied. you can give any name in the label field