Resolve GitHub – Permission denied (publickey)


This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See gitolite, 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 | pbcopy
    • On Linux run: cat | xclip
    • On Windows (via Cygwin/Git Bash) run: cat | clip
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
    • git config --global "bob"
    • git config --global bob@... (don’t forget to restart your command line to make sure the config is reloaded)

Thats it you should be good to clone and checkout.

Further information can be found on (thanks to @Lee Whitney)

get git clone work behind proxy

git config --global http.proxy

If you are using cntlm, it would be
git config --global http.proxy localhost:3128

3128 is the port you specify cntlm is using

How to set up a GIT server on windows

You will need:

  • CopSSH 3.1.4 (the latest free version)
  • Git for Windows 1.7.10 (or later)

On the server:

  1. Install Git for Windows, selecting the “Run Git and included Unix tools from the Windows Command Prompt” when prompted. This option will install a bin folder inProgram Files\git that will be placed into your path thus taking possibly taking precedence over other tools.
  2. Open up a bash prompt and run the following commands (these hard links are necessary, because CopSSH 3.0.3 appears to have an issue with symbolic links):
    cd /bin
    ln -f ../libexec/git-core/git-upload-pack.exe git-upload-pack.exe
    ln -f git.exe git-receive-pack.exe
  3. Install CopSSH
  4. Right-click “Computer” in the start menu and select “Manage”. Select “Local Users and Groups” and proceed to create Windows users for all Git users. It is not required, but I recommend you give them passwords.
  5. Activate all the Windows users under the CopSSH “01. Activate a User” option. Untick the “Create link to user’s real home directory” option when doing so. Create new public and private keys if you don’t have keys already.
  6. If you already have private and public keys, copy them to the …Program Files\ICW\home\{username} folder and call them {username}.key and {username} Also copy the public key to …ICW\home\{username}\.ssh\ and rename it to “authorized_keys”.
  7. Create your Git repositories (git init –bare …) and make sure that you grant appropriate access rights to the repository folders for all users created in step 4. (If a user does not have write access to the repository folder then an attempt to push to the repository will fail.)
  8. If you need remote access to the server, forward the SSH protocol (port 22, UDP and TCP) from your router to the server.
  9. Reboot the server so the changes to the Path environment variable can take effect.

On the workstation:

  1. Copy the private key generated in step 5 (or the one you used in step 6) to the .ssh subfolder in your user profile (typically c:\Users\Administrator\.ssh) and rename it to “id_rsa”.
  2. If you’ve generated the private key with a passphrase and you wish to remove it, run “ssh-keygen -p” in a command prompt and specify a blank new passphrase. If you don’t remove the passphrase you will be prompted for the password every time you interact with the server.
  3. If you’re using TortoiseGit, remember to specify in the installer that you’re using OpenSSH.
  4. To check out a repository: git clone {username}@{servername}:{repodriveletter}:/{repopath}

See Also

Once you have your sever setup and the users enabled through CopSSH, check out theofficial git docs for a more detailed explanation of actually setting up your repos on the server and then doing your initial commits from your workstation.