문제

I'm using BitBucket and SSH in RedHat.

Since I'm behind a corporate firewall, I'm using corkscrew to use our proxy and login.

When I do:

ssh -T bitbucket.org

Everything works and I get the

Logged in as username. You can use git or hg to connect to Bitbucket. Shell access is disabled.

But when I try to clone from my repo:

git clone git@bitbucket.org:myUser/myRepo.git

I get:

ssh: Could not resolve hostname bitbucket.org: Name or service not known
fatal: The remote end hung up unexpectedly

The repo is set to SSH and I can clone from my Windows machine, using the exact same settings with Git Bash.

What am I missing?

Update 1: As was pointed out below, git clone is not using my SSH configs at all. I can run ssh directly and it works, but git clone fails to even connect to the server. Why would git not use SSH?

도움이 되었습니까?

해결책

The problem is that you're running git clone under sudo, which means you're running it under the root account, not under your own account.

Since you're not running under your own user account, git doesn't have access to your account's ssh configuration. The git clone command is using ssh, it's just using it with the root account's settings, not with yours.

You said in a comment that you're cloning into a subdirectory of the Apache root folder. That folder is owned by the root account, so of course your account doesn't have permission to write to it.

In general, you shouldn't use the root account for anything that you can do from a non-root account, just as a matter of safety. If you can run the git clone command from your own user account, you have less risk of doing something that breaks your system, and ssh will use your personal configuration. (Modifying root's ssh configuration will do the job, but I don't think it's a good idea.)

If you want to avoid running git commands as root, you need to do the git clone into a directory that you have permission to write to.

One solution is, after you're created your directory under the Apache root directory, to use sudo chown to change the ownership of that directory to your account. You'll then be able to write to that directory, including running git clone without sudo.

Or you can use sudo chown to change just the group ownership of the directory to some group you're a member of -- probably a group created for this purpose. Then use chmod g+w to grant group write permission. Now you'll be able to write to the directory even though it's still owned by root.

Or you can just clone into a subdirectory of your home directory, and then use sudo ln -s to create a symbolic link to your directory under the Apache root directory. (A drawback of that is that it's not obvious, by looking under your home directory, that Apache depends on this subdirectory.)

다른 팁

Turns out git clone was using the global SSH settings instead of my user's settings. So I had to create new keys at /etc/ssh/ and add my corkscrew proxy settings in /etc/ssh/ssh_config.

I'm still a Linux newbie so I could be wrong, but I'm going to assume this happened because I have to do sudo git clone. Maybe this forces the terminal to use global settings instead of user settings.

I'll check with our IT department to confirm this.

In any case, if you have similar issues, check which SSH settings git is using, global's or user's.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top