Git push/pull fails on GitLab in Google Compute Engine

不问归期 提交于 2019-11-30 21:56:27
ʰᵈˑ

You need to create an SSH tunnel to communicate with GitLab.

1. Log into your development server as your user, and create a key.

ssh-keygen -t rsa

Follow the steps, and create a passcode (that you can remember) as you'd need this to pull and push code from/to GitLab.

2. Now that you've created your key, we can copy it;

cat id_rsa.pub

Copy the output of that command (including ssh-rsa), and add it to your GitLab profile. (http://my-gitlab-server.com/profile/keys/new).

3. Ensure you have the correct privilege to the project(s)

Ensure you are at role developer at the very least. (Screengrab of roles: http://i.stack.imgur.com/DSSvl.jpg)

4. Now, copy the project link

Go into your project, and find the SSH link in the top right;

5. Now back to your development server

Navigate to your directory where you'd like to work, and run the following;

$ git init
$ git remote add origin <<project_url>>
$ git fetch

Where <<project_url>> is the link we copied in step 4.

You will be prompted your password (this is your ssh key password, not your server password) and to add the host to your known_hosts file. After that, the project will start to download and you can enjoy development.

I did these steps on a CentOS 6.4 machine with Digital Ocean. But they shouldn't differ from using Google CE.

Edit

Quote from Marty Penner answer as per this comment

Solved it! Thanks to @sxleixer and @Alexander Wenzowski for figuring this out.

Apparently, SELinux was interfering with a non-standard location for the .ssh directory. I needed to run the following commands on the Compute Engine instance:

sudo yum -y install policycoreutils-python # Install the `semanage` tool
sudo semanage fcontext -a -t ssh_home_t "/var/opt/gitlab/.ssh/authorized_keys" # Allow the nonstandard ssh_home_t

See the full thread here:

Google Cloud Engine. Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

Marty Penner

Solved it! Thanks to @sxleixer and @Alexander Wenzowski for figuring this out.

Apparently, SELinux was interfering with a non-standard location for the .ssh directory. I needed to run the following commands on the Compute Engine instance:

sudo yum -y install policycoreutils-python # Install the `semanage` tool
sudo semanage fcontext -a -t ssh_home_t "/var/opt/gitlab/.ssh/authorized_keys" # Allow the nonstandard ssh_home_t

See the full thread here:

Google Cloud Engine. Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

UPDATE: It seems GitLab may already have a solution: run sudo gitlab-ctl reconfigure. See here: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#git-ssh-access-stops-working-on-selinux-enabled-systems

In my situation the git user wasn´t set up completely. If you get in your log files messages like "User git not allowed because account is locked" (Under Centos or Redhat it´s /var/log/secure) than you simply need to activate the user via "passwd -d git"

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