i how can i solve this error "Permission denied (publickey)." when i typed "git push live master" ???

February 11, 2017 31.1k views
Deployment Ubuntu

i try to deploy my project on digitalocean hosting , i follow this link , http://www.refactoru.com/blog/setting-up-push-to-deploy-on-digitalocean
every thing is ok , but when i typed "git push live master " on git bash on my local repo i get error
$ git push live master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
i searched for this problem and tried many solution but it didnot work,
notes : i work on windows OS , so i can connect to ubuntu digitalocean server with putty without any problem ..
i know the problem related with authentication , but i don't know how i solve it ???
plz help me....

5 Answers

Make sure you set remote location correctly. What does Git service you use? Is it GitHub or something other?
To check did you set remote location correctly, execute git remote -v in project directory (in same directory you did git push live master).

  • git remote -v

If you use GitHub, output should be like one of this two:

Example output 1 - Remote listing - Git
live    https://github.com/your-github-username/repo-name (fetch)
live    https://github.com/your-github-username/repo-name (push)
Example output 2 - Remote listing - Git
live    git@github.com:your-github-username/repo-name (fetch)
live    git@github.com:your-github-username/repo-name (push)

In case of first output, you should be asked for username and password once you try push. For second, make sure you have set up SSH keys correctly. If you don't have SSH key, you can follow GitHub guide to do so.
If you use GitHub and don't match above pattern, you made some mistake. Also, once again, make sure you typed your username and repo name correctly.

thanks a lot xMudrii for your response , but can you tell me if my thinking is correct or not :
when i added live brunch i gave it the path on the Ubuntu hosting server like this :
git remote add live root@x.x.x.x:/opt/adviser.git where x.x.x.x is Ubuntu hosting server IP Address
so when i typed git remote -v i get :
live root@x.x.x.x:/opt/adviser.git (fetch)
live root@x.x.x.x:/opt/adviser.git (push)
origin https://github.com/myname/adviser.git (fetch)
origin https://github.com/myname/adviser.git (push)
is that correct , i add remote brunch with my hosting server path depend on this link https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps
please help , i need any idea that help me ....

by Caio Vaccaro
This article will teach you how to use Git when you want to deploy your application. While there are many ways to use Git to deploy our application, we'll focus on the one that is most straightforward.

Hello there.

It should be correct. In case of Hooks, this is how you want to do it.
First I would verify, do you have access to Ubuntu Server from Git Bash. To do so, use ssh command:

  • ssh root@droplet-ip

If that doesn't show error (for example Permission denied (publickey).), that means this part is OK.
However, if error appears, make sure you have configured correctly SSH key on server and on client.

In case this is not a problem, make sure you created repository on Ubuntu Server correctly.
You could use How To Use Git Hooks To Automate Development and Deployment Tasks instead of DO tutorial you linked in answer, as this is newer.

by Justin Ellingwood
Git is a very robust and mature version control system that has seen great adoption in recent years. One of git's great features is its ability to use "hooks" to call arbitrary scripts when certain git events occur. In this guide, we'll discuss the general idea behind git hooks, talk about how to work around some of its inconsistencies, and demonstrate some implementations that you can use in your development process.

yes, error is Permission denied (publickey)
i can connect to server from putty and ssh key is accepted
but when i connect from git bush , i get this error ..
what can i do ? i think my ssh keys configuration is correct ..
when i use this command :
$ ssh -v root@x.x.x.x
OpenSSH7.1p2, OpenSSL 1.0.2h 3 May 2016
debug1: Reading configuration data /etc/ssh/ssh
debug1: Connecting to x.x.x.x[x.x.x.x] port 22.
debug1: Connection established.
debug1: keyloadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/idrsa type -1
debug1: key
loadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/id
rsa-cert type -1
debug1: keyloadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/iddsa type -1
debug1: key
loadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/id
dsa-cert type -1
debug1: keyloadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/idecdsa type -1
debug1: key
loadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/id
ecdsa-cert type -1
debug1: keyloadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/ided25519 type -1
debug1: key
loadpublic: No such file or directory
debug1: identity file /c/Users/DELL/.ssh/id
ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH
6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH6.6.1* compat 0x04000000
debug1: Authenticating to x.x.x.x:22 as 'root'
debug1: SSH2MSGKEXINIT sent
debug1: SSH2MSGKEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2MSGKEXECDHREPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:NjWN9e7YUzgW8nluM9DYyrfQQ5dNwJImkhfI6nBpccY
debug1: Host 'x.x.x.x' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/DELL/.ssh/knownhosts:4
debug1: SSH2
debug1: expecting SSH2
debug1: SSH2
debug1: SSH2
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/DELL/.ssh/id
debug1: Trying private key: /c/Users/DELL/.ssh/iddsa
debug1: Trying private key: /c/Users/DELL/.ssh/id
debug1: Trying private key: /c/Users/DELL/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

i save my private key as c/Users/DELL/.ssh/id_rsa but it dose not work , what can i do ??
i appreciated your help ..
this is my first experiment as web developer

  • Are you sure you have your keys in right location?
    Above output is indicating that it can't find your key. Make sure you have it in C:\Users\DELL\.ssh\id_rsa. Also make sure that key is called id_rsa and not something other.

    As a last resort, you can try generating new key, directly from, Git Bash and adding it to server authorized keys.
    You can follow steps from Initial Server Set Up - Step 4 tutorial. You will have to copy key manually using Putty.

    by Mitchell Anicas
    When you start a new server, there are a few steps that you should take every time to add some basic security and give you a solid foundation. In this guide, we'll walk you through the basic steps necessary to hit the ground running with Ubuntu 16.04.
Have another answer? Share your knowledge.