I´m having trouble with GitHub. I´ve playing around with a remote repository of Git.
When I now try to make any changes to the remote directory, i.e.
git remote show originor
git push -u origin masterI get this error
Permission denied (publickey). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists. Ulrichs-MacBook-Pro:coredatatest ulrichheinelt$ git push -u origin master Permission denied (publickey). fatal: Could not read from remote repository.
I would be happy, when I could start again with a new (empty) remote directory. Or is there a way, to fix this error?
This are my first steps with GitHub, started yesterday... Many thanks in advance!
Edit 1
my settings at
...
Edit 2
too early happy :-(
After setting the SSH and GPG keys, the errors are still the same. :-/
Edit 3
I think that's right so, but still the same...
911 Answers
- Generate SSH key using
ssh-keygen -t rsa -b 4096 -C "your email". - Copy the output of
cat ~/.ssh/id_rsa.pubto your clipboard - Paste the above-copied output to the form at
Update: If you are still facing "ssh: connect to host github.com port 22: Connection timed out", then follow the below steps.
Check the connection, mostly it will time out
$ ssh -T
ssh: connect to host github.com port 22: Connection timed outCheck the same by providing optional param port
$ ssh -T -p 443
Hi <user_name>! You've successfully authenticated, but GitHub does not provide shell access.Update the SSH settings
$ vim ~/.ssh/config
# Add github in the know hosts
Host github.com Hostname ssh.github.com Port 443Check the connection, mostly it will connect this time
$ ssh -T
Hi <user_name>! You've successfully authenticated, but GitHub does not
provide shell access. 5 - On your GitHub profile there is an
Edit Profilebutton.
It is located on top-right corner of the webpage. - Press it and you will see left
Personal Settingsmenu. - Inside that menu find
SSH and GPG keysoption and press it. - You will see an option
New SSH keyto add new key.
generate your key
ssh-keygen
Visualize your keys
ls ~/.ssh
id_rsa id_rsa.pub
Start the agent
eval `ssh-agent`
Add your key to the agent
ssh-add ~/.ssh/id_rsa
For me I had to set what host to use what SSH key.
In your local machine SSH folder, usually under ~/.ssh create/edit the file called config using your preferred editor like vim or gedit
vim ~/.ssh/configand add the following with your git Host, HostName, and ssh IdentityFile (your ssh private key file path):
Host gitlab.example.com HostName gitlab.example.com IdentityFile /home/YOURUSERNAME/.ssh/id_rsa 0 I was having the same problem with my ssh connection. I tried to work it through ssh, but couldn't find a working solution for it. So, in that case, I changed my remote URL from SSH to HTTPS. I used the command: $ git remote set-url origin .
You can see your remote url changed using:$ git remote -v.
You can find more detail on Here
This will change your remote URL to HTTPS so you will now have to type your GitHub username and password to push your project to the remote repo. I know ssh is easier than HTTPS meaning that you don't have to type out your username and password, but this might be helpful if you didn't find any solution for fixing it through ssh, and you are in a rush to push your code to your repo.
1On Windows I'd the problem when using git in powershell or command prompt. Using Git Bash on Windows solved it for me as it allows for ssh-agent to properly run in the background and allow the SSH credentials forwarding necessary to make this work.
Following the instructions at this link in Git Bash worked for me:
For those on Windows and still cannot get this figured out even though following the solutions above. I followed these to make it work.
- Go to C:\Users<accountName>.ssh or just do cd to this folder in command prompt
- Generate SSH key using
ssh-keygen -t rsa -b 4096 -C "your email"in the command prompt - Important aspect in the second step is that leave everything to default and add no passphrase too. Keep pressing enter untill the key is generated. I was changing the name of the file and adding passphrase and it wasn't working for me that way. Two files namely id_rsa and id_rsa.pub will be created
- Copy the output of
type id_rsa.puborcat id_rsa.pubfor linux to your clipboard - Paste this key in the SSH keys under git or bitbucket account
- Close the CMD and try using git clone now and it should work
*I didn't use ssh-add id_rsa as it is done to add this private key(id_rsa) into a vault
I solved the same issue before by adding the file below in the key path.
I have created the keys using git bash (ssh-keygen) and this automatically saved the key into C:\Users\{username}\.ssh folder.
I then created a file "config" without extension and added the code below:
Host * PubkeyAcceptedKeyTypes +ssh-rsaNow, try to clone again using git clone command.
make sure you have named the "public key" and "private key" files properly; precisely like "id_rsa" and "id_rsa.pub". This is something that you can find in your users/.ssh folder.
add the public key in GitHub
Restart your terminal ( bash supported) and try to clone again
if you have the write access to the repo, you should be good to go after these changes.
Talking from experience (after spending an hour), I could not find any info on any forum that stated that we have to explicitly keep the name of the private and public file as mentioned above.
Happy coding!
1If any of you facing same kind of issue on Bitbucket then here is the solution:
Issue:
------
Demo@L90TQCLQ MINGW64 /u/works (master)
$ git clone ssh://:5449/rem/jenkinspipeline.git
Cloning into 'jenkinspipeline'...
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Solution:
Demo@L90TQCLQ MINGW64 /u/works (master)
$ cat < ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC99aqMXtBpVvCQb6mezTHsftC3CFY9VOpGaNmckmcTzXoOOWOheeM9V2NTrOWxpbE3UNdL/6ZnmPyv5EI2zPMPstVIP5jAqcmxOvGc2zxy4wHeGTgrP6UaXs2nLScV4E7+rmdaVtSsfOa1i+eU2eg4UnIJpRLtGD6N+hMKJXaXWpGfQ79USiPhPQKDGOz3PeEDggyvHs7HUzaKZpwEeIKYOSDXsvDwTJ6s5uQ30YfX3eoQbAis8TJeQejAmkuu62oSOs5zFJMSTAzakiyXW/xCUsLrnUSzxmBKO2BIA/tSTrqW/Gj0VhDniDFGwGz0K1NfLzfEJLWKvdB2EJWVFjEd
Goto: 1) Add keys Copy/paste the id_rsa.pub key value there:
Done!
Now you can able to clone the git repository
KDemo@L90TQCLQ MINGW64 /u/works (master) $ git clone ssh://:5449/rem/jenkinspipeline.git Cloning into 'jenkinspipeline'... remote: Enumerating objects: 1146, done. remote: Counting objects: 100% (1146/1146), done. remote: Compressing objects: 100% (987/987), done. remote: Total 1146 (delta 465), reused 0 (delta 0) Receiving objects: 100% (1146/1146), 149.53 KiB | 172.00 KiB/s, done. Resolving deltas: 100% (465/465), done.
In my short experience using git with linux, I found there were two simple answers to this error.
run these commands in this order
git remote set-url --add origin <
git remote set-url --delete origin <:username/repo>This will reconfigure your config file to use HTTPS origin instead of SSH.
now try running push or pull commands.
OR
Reboot your linux VM (if you're using one) and/or host machine. Rebooting has resolved the issue for me more than once.