ingydotnet / git-hub

Do GitHub operations from the `git` command
MIT License
794 stars 62 forks source link

I encounter a permission issue while cloning #212

Closed eduOS closed 8 years ago

eduOS commented 8 years ago

After I enter git hub clone ingydotnet/git-hub I meet a permission denied (publickey) error. It reads Could not read from remote repository, please mak esure you have the correct access rights and the repository exists.. I suppose I may get wrong by two means: 1) the name or the owner of the repository is wrong. But I find it is not. 2) I have not set the configure file right. Here is what the .config file has:

[git-hub]
login = eduOS
api-token = my token
use-auth = true
json-lib = json-perl.bash

Could you please tell me where the problem lies? Thanks in advance.

eduOS commented 8 years ago

It guides me to use -v for more information. And I conjecture maybe I should change git@github.com to https:// format.

perlpunk commented 8 years ago

If you run the command with -v you can see what the clone command is. It clones via ssh. Can you clone directly via ssh?

perlpunk commented 8 years ago

I guess a --http option would be helpful...

eduOS commented 8 years ago

In most cases I cannot given that I am not allowed to. But I can use git clone git:// or git clone https:// for all public repositories. Why should git-hub only allow the ssh protocol?

perlpunk commented 8 years ago

Or maybe a protocol config variable would be more helpful. I think most users would want to use ssh to work with the cloned repository, but on a machine where you don't have a key, you would want http for every repository.

eduOS commented 8 years ago

Oh, get it. I have not set a global ssh key. But for this problem I've solved it by adding the following script to the .zshrc:

gitclone(){
    git clone https://github.com/$1/$2.git
}

But I'd better add a ssh key. Thanks.

eduOS commented 8 years ago

@perlpunk Sorry. I've refreshed the ssh key but failed to run it around. Could you please tell me how to set the ssh key as you said? I followed this tutorial: http://help.github.com/articles/generating-an-ssh-key. Many thanks.

perlpunk commented 8 years ago

You need to do three things:

If you followed the tutorial, maybe you could say what you have done exactly so far?

eduOS commented 8 years ago

I thought the problem lies in the second step. Here is the setting in the ssh config file:

Host eduOS
HostName github.com
User git
IdentityFile ~/.ssh/key_for_github

Since I have more than one account on GitHub I changed the host name to my account name.

eduOS commented 8 years ago

PS: I can push changes to my repo without entering password and account name.

[remote "eduos"]
    url = git@eduOS:eduOS/myrepo.git
    fetch = +refs/heads/*:refs/remotes/eduos/*

git push eduos master:master

perlpunk commented 8 years ago

I see. git-hub clones repositories with the hostname github.com. It's not possible to confiure that right now. Also for other commands which interact with the repo it expects the hostname to contain github.com.

What would work is setting the host alias manually to something like github.com-username. For repos which are already cloned, then some git-hub commands like git hub repo should work like expected. But this wouldn't work for cloning. Also, git-hub only supports one user/token in the global config right now.

So to really support different github users, we'd need to

So for now, I'm afraid you're basically restricted to one user or a lot of manual work :-/

perlpunk commented 8 years ago

Or, well, a more pragmatic solution for now could be to create a small wrapper script for each user:

GIT_SSH_COMMAND="ssh -i identityfile" GIT_HUB_USER_DIR=~/.git-hub-username \
  git hub "$@"

edit: use GIT_HUB_USER_DIR instead

eduOS commented 8 years ago

Thanks.

eduOS commented 8 years ago

@perlpunk I've tackled it by adding a default ssh key with the host name as github.com. It works well.