Search code examples
gitopenssh

clone and push to remote server repository


I have a remote server with a git repository ready to be cloned... The problem is that I need to access that server using ssh with a key file authentication that i have saved on my local machine...

I've created an empty local folder and I make:

git clone ssh://username@45.645.465.12:/path_to_my_rep/.git

But, of course, I am getting a permission denied error.. How can I say to git where to pick my ssh key file???

I have tried creating a conf file on ~/.ssh/conf and adding this lines:

Host 45.645.465.12
    Hostname 45.645.465.12
    IdentityFile    ~/.ssh/myKeyFile.pem
    IdentitiesOnly yes

But I am getting this error:

Cloning into 'gestioner'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Solution

  • I updated my conf file under ~/.ssh/ and it looks like this:

    Host myhost
        User myUser
        IdentityFile /path_to_my_key_file
    

    My main mistake was that i was running git clone as root and because of that openSSH was not reading my conf file under home/user/ but under /root/...

    After correcting this 2 things git clone worked just fine :)