Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't connect to github via ssh

Tags:

I tried to clone one of my repositories on github from my newly installed linux machine running manjaro with fluxbox. i set up the user.name and user.email and uploaded the correct ssh key. but i always get

The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? 
Host key verification failed.
fatal: Could not read from remote repository.

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

I googled it and found that i should do ssh-keygen -R github.com which should delete github from my known_hosts file but the known_hosts file doesn't even exist yet, because i just finished setting up a new linux install.

so i tried ssh -vT git@github which gave me

ssh -vT [email protected]
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.252.128] port 22.
debug1: Connection established.
debug1: identity file /home/masterkraft0r/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/masterkraft0r/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
The authenticity of host 'github.com (192.30.252.128)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? 
Host key verification failed.

which is way over my head. can somebody tell me what went wrong and maybe how to fix this mess?

like image 423
Benjamin Avatar asked Sep 03 '15 23:09

Benjamin


People also ask

How do I fix my SSH key in GitHub?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

How do I fix permission denied GitHub?

Always use the "git" user$ ssh -T [email protected] > Permission denied (publickey). If your connection failed and you're using a remote URL with your GitHub username, you can change the remote URL to use the "git" user. You should verify your connection by typing: $ ssh -T [email protected] > Hi username!


2 Answers

Did you try to add github as known host?

If you have an existing known_hosts file and do not want to overwrite (as @Puce suggested in the comment), use this.

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

This will add the rsa key to the end of the known_hosts.

If you have no idea what known_hosts is/means, or you never engaged with it for sure, you can simply write a new one, but note that this will remove the existing one if you had any.

ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts
like image 192
Saehun Sean Oh Avatar answered Oct 11 '22 12:10

Saehun Sean Oh


Step 1: Generate KEY

- cd   ~/.ssh

- ssh-keygen -t rsa -b 4096 -C "[email protected]"

NOTE - Keys need to be only readable by you:

chmod 400 ~/.ssh/id_rsa

If Keys need to be read-writable by you:

chmod 600 ~/.ssh/id_rsa

Step 2: Check the Contents and copy

cat ~/.ssh/nameOfFile.pub | pbcopy

Step 3: Configure your SSH key into Bitbucket (similar applies to Github)

GOTO settings => SSHKEY

- Add what you copied in Step 2 and give it a name

Step 4: Clone your repository using SSH protocol

git clone [email protected]:{username}/repo.git

git clone [email protected]:{username}/repo.git

This should work BUT

If you keep getting this error

[
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
]

Follow this steps.

i. ssh -T [email protected] OR ssh -T [email protected] depending on which you are using { This will test your connection to Bitbucket OR Github).

ii. If you do not see a message similar  to (logged in as username.). Go to the next step

iii. ssh-add ~/.ssh/identity (identity is whatever name you saved the file when generating a key)

iv. You will get this message (Identity added: /path to ssh file/.ssh/mywork ([email protected])
v. You can now clone your repository.
like image 45
Gerald Avatar answered Oct 11 '22 11:10

Gerald