How to Fix Permission Denied for .Git/ Directory When Performing Git Push

How to fix permission denied for .git/ directory when performing git push?

On the server I ran sudo chown -R git:git /srv/git/ - this fixed my problem but I am wondering if this was the correct thing to do?

Absolutely. The problem previously was that the git user, who you're logging in as via SSH, could not write to the repository.

Depending on your needs, you may consider different combinations of users and SSH keys, or one of the many additional programs (gitolite etc) that can be used to more finely control access.

Permission denied error on Github Push

  • click fork button on original github project page
  • clone your forked repository instead original
  • push to it
  • press Pull Requests button on your repository
  • create it
  • wait for original author to accept it

Github remote permission denied

Unable to access https means: this has nothing to do with SSH (and switching to SSH, while possible, does not explain the original issue)

This has to do with credential caching, meaning Git will be default provide the credentials (GitHub account and password PAT Personal Access Token) of the old account while you are trying to push to the new account.


Reminder, most Git repository hosting service uses token as password, not your actual user account password.

For instance, GitHub no longer accept password since Aug. 2021.


See if you have a credential helper that would have cached your (old account) credentials (username/password) used to authentication you.

git config credential.helper 

On Mac, as commented by Arpit J, just goto/open your keychain access->search for github.com related file->and edit credentials there.

https://help.github.com/assets/images/help/setup/keychain-access.png

See "Updating credentials from the OSX Keychain"

On Windows (And, in 2021, possibly Linux or even Mac), that would be the Windows Credential Managers GCMC: Git Credential Manager.

Open the Windows Credential Store, and see if the first user is registered there: delete that entry, and you will be able to authenticate with the second user.

(Here is an example for BitBucket)

https://kwilson.io/blog/wp-content/uploads/2015/01/4-store.png


In command-line (see git credential), for a manager core credential helper:

  • Get the old password or token:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \
    git credential-manager-core get

    # output:
    protocol=https
    host=github.com
    username=<me>
    password=<old_password_or_token>
  • Remove the old password:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \
    git credential-manager-core erase

(Replace <me> by your GitHub user account name)

Git: How to solve Permission denied (publickey) error when using Git?

If the user has not generated a ssh public/private key pair set before

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)

First start by setting up your own public/private key pair set. This
can use either DSA or RSA, so basically any key you setup will work.
On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
  • On OS X run: cat id_rsa.pub | pbcopy
  • On Linux run: cat id_rsa.pub | xclip
  • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil)
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
  • git config --global user.name "bob"
  • git config --global user.email bob@...
    (don't forget to restart your command line to make sure the config is reloaded)

That's it you should be good to clone and checkout.

Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney)
[1]: https://github.com/sitaramc/gitolite

-

If the user has generated a ssh public/private key pair set before

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

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

  • On your GitHub profile there is an Edit Profile button.

    It is located on top-right corner of the webpage.
  • Press it and you will see left Personal Settings menu.
  • Inside that menu find SSH and GPG keys option and press it.
  • You will see an option New SSH key to add new key.

GitHub Error Message - Permission denied (publickey)

GitHub isn't able to authenticate you. So, either you aren't setup with an SSH key, because you haven't set one up on your machine, or your key isn't associated with your GitHub account.

You can also use the HTTPS URL instead of the SSH/git URL to avoid having to deal with SSH keys. This is GitHub's recommended method.

Further, GitHub has a help page specifically for that error message, and explains in more detail everything you could check.

Git gives me a Permission Denied error when writing files that I am pulling

Run the Git Bash or the console you are running, with Run As Administrator



Related Topics



Leave a reply



Submit