For some repositories at work I get the following message when I try to push my commits:

GitError! Could not read from remote repository.  [Type `$' for details]

The details read:

128 C:/Program Files/Git/mingw64/libexec/git-core/git.exe … "push" "-v" "origin" "master:refs/heads/master"
Pushing to ssh://[email protected]

fatal: Could not read from remote repository.

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

Any idea what the problem could be? Running the above git command from a git-bash (minus those tripple-dots) also works. In fact, that's my workaround. Compose the commit with magit and just type git push in a git-bash. Pushing to github.com repository on the same machine works from magit.

  • Type TAB on the 128... line to actually see the details.
    – tarsius
    Commented Nov 29, 2017 at 10:26
  • Thanks, I edited the question accordingly. I'm mainly puzzled by the fact that git-bash doesn't give me such an error.
    – B_old
    Commented Nov 29, 2017 at 10:37
  • Have you read this? github.com/magit/magit/wiki/Pushing-with-Magit-from-Windows
    – npostavs
    Commented Nov 29, 2017 at 11:16
  • 2
    Since you are pushing to ssh://..., you must be using SSH keys to authenticate against the repository. I'd start by making sure that git-bash expands $HOME to the same directory as M-x getenv HOME. Or, perhaps, you are running an ssh-agent program that manages the keys for you, but it runs in the git-bash session, and not in Emacs (so you would need to start ssh-agent in Emacs too).
    – wvxvw
    Commented Nov 29, 2017 at 11:36
  • @wvxvw: That was the perfect hint! Emacs and git-bash were seeing different HOME variables. The easiest way was creating a symlink to .ssh so that emacs sees it. Problem solved. Thanks.
    – B_old
    Commented Nov 29, 2017 at 13:17

4 Answers 4


The problem was that emacs was seeing a different $HOME variable than git-bash and could therefore not find the ssh-keys. Thanks to @wvxvw for pointing me in the right direction. After creating a symlink everything works now.


I had the same error message until moments ago. I had to install the package ssh-agency. A solution that is also documented in the link provided by @npostavs

In spacemacs you do that by adding it to dotspacemacs-additional-packages.

  • Can you explain more how you did it? I still have the same problem!
    – Hasan Sh
    Commented Jun 30, 2020 at 12:04

Working with remotes used to be fine until Emacs was updated to 26.3 from 26.2 on my Fedora 30 computer. The solution is to set the variable SSH_AUTH_SOCK for Emacs:

  1. Check the value of this variable on your system

    $ echo $SSH_AUTH_SOCK
  2. Set it from Emacs with value from above. For me it's "/run/user/1000/keyring/ssh".

    M-x setenv SSH_AUTH_SOCK RET /run/user/1000/keyring/ssh

Source: https://github.com/syl20bnr/spacemacs/issues/10969

  • Thanks. Turns out my shell's SSH_AUTH_SOCK differed from that in Emacs. Setting it in my init.el solved the problem.
    – hraban
    Commented Apr 7, 2021 at 11:40

I got the same error. For me, the git cli was working fine from the terminal but failed to work inside Emacs. I opened an interactive shell and ran the same command and the error was much clear:

sibi { ~/github/dotfiles }-> git fetch origin
Bad owner or permissions on /home/sibi/.ssh/config
fatal: Could not read from remote repository.

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

Fixing it was much simpler after that:

$ chmod 600 ~/.ssh/config

And after that all the magit operations start working as usual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.