Permission denied publickey Git

Permission denied publickey Git

This most common annoying error while connecting to Git from remote computer and if you are first timer like me then it will take sometime to understand, it does not matter if you are good Googler. You get exception similar to below:

Branch Name: javahonk
working directory /apps/javahonk
Folder build exists. deleting it for clean  build
executing: rm -rf  build
executing: git clone git@github.com/javahonk/SpringHibernateSysbaseIntegration.git .
Initialized empty Git repository in /apps/javahonk/build/.git/
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
command execution failed: git clone https://github.com/javahonk/SpringHibernateSysbaseIntegration.git .
  • Solution: If you want to access Git repository without using the password then you will have to generate SSH key and add public key to your Git hub account. When you generate SSH key it generates private/public pair namely: id_rsa (This is a private key) and id_rsa.pub (This is a public key). You will have to copy content of id_rsa.pub to your git hub account.
  • You could check existing and generate new SSH key using this Git tutorial
  • Once keys are generated use this documentation to add SSH to your Git account

If you are using Linux you could add SSH key in ~/.profile or ~/.bashrc file below is example of ~/.profile file:

bash-4.1$ cat .profile

#--------------------------------------------------------#
#  A sample .profile file for Korn shell and Bash users  #
#--------------------------------------------------------#
#  Courtesy of Developer's Daily                         #
#  http://www.DevDaily.com                               #
#--------------------------------------------------------#

PATH=$PATH:/usr/local/bin:/usr/gnu/bin:.

set -o vi           # enable the ability to recall previous commands with
PS1='$PWD> '        # set the prompt to display the current directory

#---------------------------------#
#  a few Korn/Bash shell aliases  #
#---------------------------------#

alias lc="ls -C"
alias lm="ls -al | more"
alias dirs="ls -al | grep '^d'"     # show the dir's in the current dir
alias h=history                     # show the history of commands issued

alias nu="who|wc -l"                # nu - number of users
alias np="ps -ef|wc -l"             # np - number of processes running
alias p="ps -ef"

# mimick a few DOS commands with these aliases:

alias cd..="cd ../.."
alias cd...="cd ../../.."
alias dir="ls -al"
alias edit=vi
alias help=man
alias path="echo $PATH"



#Add git ssh certification
eval `ssh-agent -s`
ssh-add /opt/javahonk/.ssh/id_rsa

bash-4.1$
  • In above file this is SSH certification part:
#Add git ssh certification
eval `ssh-agent -s`
ssh-add /opt/javahonk/.ssh/id_rsa

That’s it. Still you are not sure what to do, then summary is: Please generate SSH key and add that key to your Git account. If you are using different user other than the Git user as this will be the case if you are using Linux, Mac etc.. where people use super user to take build not using by their own user id but the process is same. Generate SSH key for super user and add that generated public key to your Git account.

Leave a Reply

Your email address will not be published. Required fields are marked *