Resolve Gitlab permission denied (publickey) error

Oct 1, 2017 Gitlab 中文版

To make deployment process easier, Gitlab has introduced a feature called Deploy Keys. After adding your SSH public key into it, you can utilize that key to pull your codebase without passwords in a secure way. So, I tried to leverage the feature, but I got error permission denied (publickey) after I properly set the SSH key and related settings. If you faced the same problem, this post might help you.



Resolve Permission denied (publickey) error

You might easily get the permission denied error message in different cases. In my case, I already added SSH public key into Gitlab, and set the SSH key in Unix-like system and changed the permission of it properly. But I still got this error message:

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

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

After couple retries, I found that adding a config file into .ssh folder can resolve this problem. Here is an example of the config:

Host gitlab.com
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes



You might also like:




If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)

zeckli.devforgalaxy@gmail.com   © 2015-2019 zeckli, thanks to Jekyll and GitHub.