11

Step I had done: https://help.github.com/articles/generating-ssh-keys/ follow exactly.

$ eval "$(ssh-agent -s)"
Agent pid 31944
$ ssh-add
Enter passphrase for /home/centos7/.ssh/id_rsa:
Identity added: /home/centos7/.ssh/id_rsa (/home/centos7/.ssh/id_rsa)

$ ssh-add -l
4096 ab:4d:23:23:99:ce:bb:9d:9f:9e:f9:b2:c8:1a:cd:f7 /home/centos7/.ssh/id_rsa (RSA)

However, when I run

$ git clone git@github.com:privateRepo/repo.git

Cloning into 'repo'...
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is 56:27:ac:a5:36:28:2d:36:23:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Below is the output I run

$ ssh -Tv git@github.com

OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/centos7/.ssh/config
debug1: /home/centos/.ssh/config line 1: Applying options for *github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to github.com [192.30.252.131] port 22.
debug1: Connection established.
debug1: identity file /home/centos7/.ssh/id_rsa type 1
debug1: identity file /home/centos7/.ssh/id_rsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_dsa type -1
debug1: identity file /home/centos7/.ssh/id_dsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_ecdsa type -1
debug1: identity file /home/centos7/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/centos7/.ssh/id_ed25519 type -1
debug1: identity file /home/centos7/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 56:27:ac:a5:36:28:2d:36:23:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/centos/.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/centos7/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.131]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_CTYPE = UTF-8
Hi tomkim! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 4128, received 2040 bytes, in 0.5 seconds
Bytes per second: sent 8000.8, received 3953.9
debug1: Exit status 1

As the line above showed that Hi tomkim! You've successfully authenticated, but GitHub does not provide shell access. which means I already unthenticated, but why I can't clone my repo?

Update: I can clone in my home directory, but when I try with sudo it did not work, it happen in my /var/www/html/ folder

$ sudo git clone git@github.privateRepo/repo.git Cloning into 'repo'... Warning: Permanently added the RSA host key for IP address '192.30.252.131' 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.

$ git clone git@github.privateRepo/repo.git Cloning into 'repo'... remote: Counting objects: 4741, done. remote: Total 4741 (delta 0), reused 0 (delta 0), pack-reused 4741 Receiving objects: 100% (4741/4741), 30.30 MiB | 5.83 MiB/s, done. Resolving deltas: 100% (1451/1451), done. [centos@ip-172-31-12-124 ~]$ ll total 4 drwxrwxr-x. 12 centos centos 4096 Jun 15 04:16 repo

I know I can clone with HTTPS, but I would like to solve this issue, anyone can help?

Tom Kim
  • 526
  • 1
  • 5
  • 16
  • Are you trying to clone your own repository, or somebody else's? – ChrisGPT was on strike Jun 13 '15 at 11:30
  • Yes. I do try my own repo also can't. The above example is a private repo. The git clone does not work in ssh. – Tom Kim Jun 13 '15 at 14:39
  • When you say you're trying to clone `privateRepo/repo.git`, `privateRepo` should be a *user* or *organization*, not a repository. Something like `git@github.com:user/project.git` is more accurate. Are you doing that? – ChrisGPT was on strike Jun 13 '15 at 15:10
  • Yes. I am doing that. I try to clone my own repo also not working... could it possible centos 7 setting different? This is first time I work with centos7, my Mac is working fine... – Tom Kim Jun 13 '15 at 15:28
  • I don't think that CentOS is significant. Do you always get the "Permanently added the RSA host key for IP address '192.30.252.131'" message? It's in the output of both your `ssh` and `git clone` commands. – ChrisGPT was on strike Jun 13 '15 at 16:02
  • Yes. I had the message, and I selected Yes. As you see my log above, the authentication is success when I run the debug. However when I try to clone with ssh it just not allowed. Something weird just happened – Tom Kim Jun 13 '15 at 16:36

4 Answers4

7

The answer is related user permission issue. I need to set the correct folder permission for current user.

For the git sudo issue, the answer can be found in below link:

https://help.github.com/articles/error-permission-denied-publickey/#should-the-sudo-command-be-used-with-git

Thanks Chris for looking into this question.

Tom Kim
  • 526
  • 1
  • 5
  • 16
  • After doing `ls -la` I found that by creating folder from FTP its username is different and from command prompt it is different. Created folder by FTP then its worked correctly. – mujaffars Feb 26 '16 at 12:04
  • can you elaborate on "I need to set the correct folder permission for current user"? What exactly did you do to resolve the problem? – FuzzyTree Jul 18 '16 at 18:12
  • e.g I am login as tom, I need to set the owner of the folder become tom – Tom Kim Jul 21 '16 at 08:21
5

Copy your SSH public key under your SSH directory.

cd ~/.ssh
cat id_rsa.pub

Copy the pub key and paste it under "SSH and GPG key" under GIT "settings" page.

Click your profile photo --> "Settings" --> "SSH and GPG key" , Now add the Copied text.

JimHawkins
  • 4,843
  • 8
  • 35
  • 55
Srudeep P A
  • 51
  • 1
  • 2
  • 1
    Welcome to Stackoverflow. It would be better if you checkout [How to Answer](https://stackoverflow.com/help/how-to-answer) page for future endeavor at Stack overflow. -Thank you – Momin Jan 08 '18 at 10:26
3

use this https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

then get your generated key ( start with ssh-rsa or other type ) go to your git user panel -> SSH & GPG Keys --> New SSH key -> paste your key ( fill title with any ) then press Add SSH key

Will Fix.

good luck.

0
  1. Open your terminal and run the below command step by step

    $ ssh-add -l -E sha256

  2. You will get something like this

    256 SHA256:CMY4Hfwu5CPf0xxxxx/kzsluFSyr7HhkL2b5XXXXX email@example.com (ED25519)

  3. Go to .ssh directory

    ~$ cd ~/.ssh

  4. Run this command with your id (ED25519)

    $ cat id_ed25519.pub

  5. You will get something like this (I have altered the key) ssh-ed25519

    AAAAC3NzaC1lZDI1NTE5XXXXINN9c+lXXXXXXQd1sSo2I4trq6rD/2lbBd3OrYPDoG email@example.com

  6. Copy the entire thing from point 5

  7. Open your github account -> go to setting -> SSH and GPG Key

  8. Click on new SSH key button

  9. Paste your complete key from point 5 and add any title in SSH

and you are done!!!

Md Shahnawaz
  • 556
  • 5
  • 20