671

I am trying to set git up with http://danielmiessler.com/study/git/#website to manage my site.

I have gotten to the last step in the instructions: git push website +master:refs/heads/master

I am working using the git ming32 command line in win7

$ git push website +master:refs/heads/master Bill@***.com's password: Connection closed by 198.91.80.3 fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

One problem here may be that the program is looking for Bill@***.com. when I connect via ssh to my site I have a different username( lets say 'abc'). so maybe this should be abc@***.com. If so I don't know how to change this or if I can push under an alias

12
  • 2
    I had the same issue, sometimes this error happens when git server isn't reachable or has something like "internal server error". Commented Mar 6, 2014 at 14:21
  • 7
    First please look at .git/config file and see everything is in order. It had wrong set-url and origin values for me. Commented Jun 1, 2017 at 16:59
  • Perhaps this would solve the issue: help.github.com/articles/connecting-to-github-with-ssh Commented Oct 29, 2017 at 6:47
  • A related issue: stackoverflow.com/questions/10127818/… Commented May 8, 2018 at 8:55
  • can you show me the correct order of .git/config and also the .ssh/config ... coz i'm confused abit tough. Commented Jul 13, 2019 at 13:24

65 Answers 65

604

Your ssh key most likely had been removed from ssh agent

ssh-add ~/.ssh/id_rsa 

where id_rsa is a ssh key associated with git repo

Update

You may get Could not open a connection to your authentication agent. error to resolve that you need to start the agent first by:

eval `ssh-agent -s` 
Sign up to request clarification or add additional context in comments.

14 Comments

This worked for me! I spent a long time trying to configure my ~/.ssh/config file to use different keys for different hosts, thought that this file was the problem. In the end, it must have been using the right key for the right host, but that key had been "removed". so ssh-add ~/.ssh/theKeyInQuestion got me back up and running with this repo, didnt know the key removed, or what "removed" even means but at least I was able to get authenticated again. SSH is a total mystery to me even after months of dealing with authentication issues. ssh agent issues are one more thing to be aware of!
This solved it for me, I don't understand why.. It used to work and all of a sudden not, is there a process that removes the key from the agent, can it happen on accident?
In MacBook I use ssh-add -k ~/.ssh/id_rsa
I'm getting Could not open a connection to your authentication agent..
@DanDascalescu try to use eval `ssh-agent -s` to start the ssh-agent firstly
|
324

I was facing same issue a while ago...

my .git/config had

url = [email protected]:manishnakar/polymer-demo.git 

I replaced it with

url = https://github.com/manishnakar/polymer-demo.git 

and it works now:)

13 Comments

how is this not higher ranked? git@github totally does not work for me
If the repo owner has not set up ssh keys then you will likely have this issue. The fix as indicated is to use https instead, or have the repo owner set up ssh
@smileham this switch the distant link with the repo from a ssh based auth to an https protocol (it will prompt for usr/pwd if required)
this is the correct answer, it worked instantly for me.
This is not an answer. It changes the protocol over which you authenticate. This is not a solution to ssh setup, but totally different way of talking to your git repo
|
174

You can specify the username that SSH should send to the remote system as part of your remote's URL. Put the username, followed by an @, before the remote hostname.

git remote set-url website abc@***.com:path/to/repo 

10 Comments

ps , is there a way to add the password in so I don't keep having to type it?
edit the file .git/config which has the remote url parameter
For Github, you always use the username git. Example: [email protected]:mayoff/uiimage-from-animated-gif.git Github figures out your identity by looking at what SSH key you send.
It is not clear enough and my guessing about the answer does not work.
@SaidbakR this might help you git remote set-url origin [email protected]:path/to/repo.git
|
173

Make sure you have correct url in .git/config

url = [email protected]:username/repo.git 

If it's your first push, you'll need to set up correct upstream

$ git push -u origin master 

You can check which key is used by:

$ ssh -vvv [email protected] 

The reply should contain something like this:

debug1: Next authentication method: publickey debug1: Offering RSA public key: ~/.ssh/id_rsa ... You've successfully authenticated, but GitHub does not provide shell access. 

Also it's possible to define rules for ssh in ~/.ssh/config, e.g. based on aliases:

 Host github HostName github.com User git IdentityFile "~/.ssh/id_rsa" Host git HostName github.com User git IdentityFile "~/.ssh/some_other_id" 

You can set connect to different ports, use different username etc. for each alias.

9 Comments

Thank you!! At some point when I cloned my repo, the url was set to https://github.com/user/repo.git (without [email protected]) and so it refused to use my SSH key. Maybe it's because I cloned it using GIthub for Windows originally (?)
I've had to change url = ssh://github.com/RaphaelBossek/dev-atlassian-jira-proman.git to url = ssh://[email protected]/RaphaelBossek/dev-atlassian-jira-proman.git and it worked again
Damnit, you are awesome. I tried so many other solutions. My url was https: as well :(
The -vvv hint was helpful for me. Now I see that it's saying "Connection closed by XXX.XXX.XXX.X port 22".
Ahhh, DeployHQ says "BitBucket is currently experiencing minor service problems. Please check their status page for more information. status.bitbucket.org" Bingo.
|
56

I had a wrong ssh private key for Bitbucket along with the right one in ssh agent.

Deleted all keys first

ssh-add -D 

Then added just the right key.

ssh-add ~/.ssh/id_rsa 

5 Comments

what is id_rsa ?
@S.M.FazleRabbi id_rsa is the default name for the key file when you create the ssh key
Of course your key may not be called id_rsa in which case use the name of your key instead.
Worked for me! I have 2 different ssh keys, for different github spaces.
This is the most likely correct answer to this question. The original poster clearly was able authenticate via SSH, but was then unable to access the repository. This happens if you have more than one SSH key that is able to authenticate (e.g. work and personal). SSH will authenticate using the first one allowed, and this becomes your identity on the server, but may not have read or write permission to the repository.
34

Make sure ssh-agent is running by executing the following command on your terminal:

eval $(ssh-agent -s) 

Source: Github documentation

3 Comments

This fixes an issue for me as well. Thanks
This fixed it for me as well. Is there something I should be doing to make sure it is running in the future? Like put it as an entry in my .zshrc file?
This did it for me
29

This is usually caused due to the SSH key is not matching with the remote.

Solutions:

  1. Go to terminal and type the following command (Mac, Linux) replace with your email id.

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

  2. Copy the generated key using following command starting from word ssh.

    cat ~/.ssh/id_rsa.pub

  3. Paste it in github, bitbucket or gitlab respective of your remote.
  4. Save it.

Comments

28

Try removing the GIT_SSH environment variable with unset GIT_SSH. This was the cause of my problem.

6 Comments

Works.. I wonder where I got GIT_SSH environment variable from :)
For windows remove GIT_SSH environment variable from advanced options menu. Worked for me.
How? What do I write in the terminal to do that?
Fixed the issue for me as well
Fixed it for me too. But why does this cause the problem in the first place?
|
21

I had the same problem.

This error means that you have not specified your remote URL location upon which your code will push.

You can set remote URL by 2 (mainly) ways:

  1. Specify remote URL via executing command on Git Bash.

    • Navigate to your project directory

    • Open Git Bash

    • Execute command:

      • git remote set-url origin <https://abc.xyz/USERNAME/REPOSITORY.git>
  2. Mention remote URL direct in config file

    • Navigate to your project directory

    • Move to .git folder

    • Open config file in text editor

    • Copy and paste below lines

      • [remote "origin"] url = https://abc.xyz/USERNAME/REPOSITORY.git fetch = +refs/heads/*:refs/remotes/origin/*

For more detailed info visit this link.

1 Comment

thanks so much!!! I tried everything and this worked finally.
13

Another workaround:

Sometimes this happens to me because of network problems. I don't understand the root problem fully, but switching to a different sub-network or using VPN solves it

3 Comments

Exactly my case. Wish I had read this comment. After few hours of debugging, thought of using VPN and it worked.
For me, just "trying again" worked. No idea what the hiccup was.
This is happening to me after switching ISPs. That must be it.
13

Pretty straightforward solution that worked for me, see below:-

Problem
$ git clone [email protected]:xxxxx/xxxx.git my-awesome-proj Cloning into 'my-awesome-proj'... ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. 
This should also timeout
$ ssh -T [email protected] ssh: connect to host github.com port 22: Connection timed out 
This might work
$ ssh -T -p 443 [email protected] Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access. 
Override SSH settings
$ vim ~/.ssh/config # You can also manually open the file and copy/paste the section below # Add section below to it Host github.com Hostname ssh.github.com Port 443 
Then try again
$ ssh -T [email protected] Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access. 
Try cloning now (should work)
$ git clone [email protected]:xxxxxx/xxxxx.git my-awesome-proj Cloning into 'my-awesome-proj'... remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (14/14), done. remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0 Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done. 

Reference: here => Use HTTPS with Port 443

3 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
This did help me. It suddenly stopped working and this was the way to fix it.
This is what finally worked for me. Thanks!
9

I had the same error. The solution was following: I've corrected my url in .git/config. Just copied that from HTTPS clone URL. That would be something like that:

url = https://github.com/*your*git*name*/*your*git*app*.git 

It worked.

3 Comments

if i wrote this on my config file under windows os, the error arose differently, it said... "/c/Users/asus/.ssh/config: line 5: Bad configuration option: url"
using https over ssh is work fine, it asks username and password
@Kiran, that's not fine.
9

I was facing the same issue. so here's the way i resolved the same

Step 1:

create a new ssh key:-

ssh-keygen -t ed25519 -C "[email protected]" 

Step 2:

copy the ssh key on clipboard :-

pbcopy < ~/.ssh/id_ed25519.pub 

Step 3:

now paste copied ssh key to the corresponding git repository

Step 4: Start the ssh-agent in the background.

$ eval "$(ssh-agent -s)" > Agent pid 59566 

Step 5: now try accesing the repo

git clone [email protected]:username/repo-name.git 

Step 6:

if still you see the issue then check the ssh config file

vim ~/.ssh/config 

the content should look like

Host github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519 

Step 7:

Add your SSH private key to the ssh-agent and store your passphrase in the keychain

ssh-add --apple-use-keychain ~/.ssh/id_ed25519 

Step 8:

Now try again it should work

git clone [email protected]:username/repo-name.git 

Comments

9

I had a perfectly fine working git and suddenly I got that error when I tried to push to the master. As I found out, it was because the repository host had problems.

If you using GitHub or Bitbucket you can easily check the status at

https://githubstatus.com/ or https://status.bitbucket.org/

enter image description here

2 Comments

GitHub's link no longer functions. Try: githubstatus.com
GitHub down again today, thanks for mentioning this point.
8

If after"git push origin master" command u see the error "could not read from remote repository" then try this out

1.ssh-keygen -t rsa -b 4096 -C "youremail" 2.eval $(ssh-agent -s) 3.ssh-add ~/.ssh/id_rsa 4.clip < ~/.ssh/id_rsa.pub(it copies the ssh key that has got generated) 5.then go to your remote repository on github and goto settings-> SSH and GPG keys ->new SSH key ->enter any title and paste the copied SSH key and save it 6. now give git push origin master 

Comments

7

After doing some research I've finally got solution for this, you have declared a environment variable to plink.exe path. So if you remove that path, reopen the git bash and try cloning through SSH it will work.

Refer to this link

http://sourceforge.net/p/forge/site-support/2959/#204c

Comments

5

You need to use HTTPS for Git:

Type this into the Terminal:

$ git remote set-url origin abc@***.com:path/to/httpURLRepo 

Then commit:

$ git add . $ git commit -m "This is the commit message" 

1 Comment

> For me, using https instead of ssh worked: git clone gitlab.com/user/project.git
5

updated OCT 2020

In most of the case when you have more than one user access the same git server from a same client system, that time git server confused to with access key with the user both users allowed but when you fire command that time its used default user.

ssh -T [email protected] 

see which user are activatly you try to push with that user

the simple solution removes the unused user public key from the git server.

then try to git fetch or pull, push it will work for me

Comments

5

My issue was resolved by using these commands on Windows 11

1. I opened up the Git Bash command and started ssh-agent.

eval "$(ssh-agent -s)" // this command only work in git bash. 

2. Added by ssh-key

ssh-keygen -t rsa -b 4096 -C "[email protected]" //it must be 4096 ssh-add id_rsa 

3. Check properly added or not.

ssh-add -l 

4. Uploaded its public key on GitHub as (Authorization key)

cat id_rsa.pub | clip 

5. Unset any proxy and GIT_SSH variable

unset GIT_SSH git config --global --unset http.proxy git config --global --unset https.proxy 

6. Must check github.com should be resolved.

ping github.com 

7. Now check Connectivity with Github.

ssh -T [email protected] 

Output

The authenticity of host 'github.com (20.207.73.82)' can't be established. ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Hi MHamzaRajput! You've successfully authenticated, but GitHub does not provide shell access.

Comments

4

In your .git/config file

[remote "YOUR_APP_NAME"] url = [email protected]:YOUR_APP_NAME.git fetch = +refs/heads/*:refs/remotes/YOUR_APP_NAME/* 

And simply

git push YOUR_APP_NAME master:master 

Comments

4

If you use Gitlab than you might need to log in and accept Gitlab new terms, before you try to pull or push.

2 Comments

Why the downvote? At same day I solved my problem, it had something to do with new gitlab terms.
Please remove your downvote. This is a valid answer, it happend after gitlab terms change. Accepting gitlab new terms might solve the problem.
4
user@server:/etc/nginx$ cat .git/config ... [remote "origin"] url = [email protected]:user/.git fetch = +refs/heads/*:refs/remotes/origin/* ... 

  1. Use ssh instead of https.
  2. To use ssh key in git (add ssh key).
  3. If you are root, use the ssh key.

$ sudo ssh-keygen $ cat /root/.ssh/id_rsa.pub $ git init $ git add file $ git commit -m "add first file" $ git remote add origin [email protected]:user/example.git $ git push -u origin master 

Comments

4

I have tried everything including generating new key, adding to the GitHub account, editing .ssh/config and .git/config. But still it was giving me the same error. Then I tried following command and it does work successfully.

ssh-agent bash -c 'ssh-add ~/.ssh/id_rsa; git clone [email protected]:username/repo.git' 

2 Comments

As mentioned, have you tried running ssh -T [email protected]? That worked for me.
@MikeS. No I did not try that. I will try, if I face similar issue again. Thanks.
4

In my case, The bitbucket's web ssh key setup UI is confusing.

Repository Settings -> Access keys -> Add key : Error

Personal settings -> SSH keys -> Add key : Ok

The public key registration screen is mutually exclusive. You must register the public key only in one place. It seems good to unify them on one screen.

1 Comment

This was exactly my problem, it is really strange why key that is added to the the repository didn't worked.
4

I resolved this issue by change my url from

https://gitlab.com/{gitlab_user}/project_repo.git 

to

https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git 

using command

git remote set-url https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git 

Comments

3

For my case, I am using Corporate network (without internet connection) in office. In order to pull code from github, I set https proxy in gitbash and then use https instead of ssh to pull code,it works fine. However when comes to push code, the https proxy won't work. So either switch to Internet network (with internet connection) or set ssh proxy can solve the problem.

1 Comment

Yes it does the same with some free wifi in coffee places
3

In my case I was using an ssh key with a password to authenticate with github. I hadn't set up pageant properly in Windows (only in cygwin). The missing steps were to point the git_ssh environment variable to plink.exe. Also, you need to get github.com into the plink known_hosts.

 plink github.com y <then ctrl-c> 

Hope this helps!

I sure wish intellij would have given me a more useful error, or better yet asked me to type in the ssh key password.

Comments

3

I solved this issue by restarting the terminal (open a new window/tab).

So if you don't really want/need to understand the underlying problem, test method is worth a try before digging deeper :)

2 Comments

This didn't work but I had to turn off my Wi-Fi and then turn it back on.
Or, if this doesn't work, restart the computer. Especially if your setup worked properly before.
3

I meet the problem just now and fix it by: git config user.email "youremail".


update: The root cause maybe my poor network and poor proxy. I still don't know why it happened, but every time has this error, this command works!!!

Comments

2

Actually I tried a lot of things to make it work on Win7, since changing the SSH exectun fron native to build-it and backwards and the same error. By chance, i change it to HTTPS in the ".git/config" file as:

[remote "origin"] url = https://github.com/user_name/repository_name.git fetch = +refs/heads/*:refs/remotes/origin/* 

and it finally worked. So maybe it could work for you as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.