4

I have transfered my ssh key from my root to my user account by ssh-copy-id command

so now I have these files in my .ssh folder

user@user-php:~/.ssh$ ls
authorized_keys  config  id_rsa  id_rsa.pub  known_hosts

Now when I want to clone a project and actually the public key is in authorized_keys file it gives me error

user@user-php:/var/www/ts$ git clone [email protected]:/xxxx.git
Cloning into 'xxxx'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

it is not pick up public key form authorized_keys

now why it not picking up the public key and is there any way i can tell git which public key to use.

EDIT: i have also try one more thing i have copyied all the keys from root/.ssh folder to user/.ssh but it still gives Permission denied (publickey). error

2 Answers 2

9

You need to add the id_rsa.pub contents to the authorized_keys file depending on the version of OpenSSH that's installed on the server.

If authorized_keys doesn't exist, create it.

Also, make sure that you are copying the public key correctly. What I would do, transfer my id_rsa.pub to the server via SFTP, then on the server (via SSH if possible) run:

cat id_rsa.pub >> ~/.ssh/authorized_keys
0

Sorry after some search i found out that to push and pull form git you need privte key for that public key which is kept on the server. so i copied the private the to the .ssh folder and then added it to ssh-agent with

ssh-add command and then i was easily pull and push now

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .