git fetch in repo dir 'Permission denied' but working with direct link with user

一曲冷凌霜 提交于 2020-01-07 03:12:26

问题


I got an issue with accessing the external repository on gerrit through git. When I try to git fetch in cloned repository directory (clone works well) I get:

> git fetch
Permission denied (publickey).
fatal: Could not read from remote repository.

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

But when I do it directly with repository ssh address and username I get:

> git fetch ssh://username@ip:port/repo_name
remote: Counting objects: xxxx, done
remote: Finding sources: 100% (xxx/xxx)
etc...

So the direct git fetch seems to work well. I've tried to set different usernames with:

git config --global user.name "username"

But with no use - I still get Permission denied (publickey). Again - git clone works fine.

Any ideas how to fix that?


回答1:


Frist, check the current URL used to fetch:

git remote show origin

Then, if the fetch url does not match, change it using the following command:

git remote set-url origin ssh://username@ip:port/repo_name




回答2:


The user.name on Git config doesn't matter in Git fetch/clone command it's used only in Git commits.

How did you execute the clone?

Have you used the following?

git clone ssh://username@ip:port/repo_name


来源:https://stackoverflow.com/questions/42832120/git-fetch-in-repo-dir-permission-denied-but-working-with-direct-link-with-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!