使用SSH连接到自己的Web服务器上的Git存储库 [英] Connecting to Git repo on own web server with SSH

查看:144
本文介绍了使用SSH连接到自己的Web服务器上的Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2台Web服务器.在服务器A上,我安装了GitLab.

I have 2 web servers. On server A I have a GitLab installed.

在服务器B上,我刚刚初始化了一个裸Git存储库.

On server B I just initialized a bare Git repo.

现在,我想使用为此,我需要一个HTTPS或SSH网址,并且我想使用SSH.

For this I need an HTTPS or SSH url, and I want to do it with SSH.

问题1:我需要在此处插入什么网址?我想应该是ssh://ssh-user@server-b.com:path-to-git-repos/project.git之类的东西.是吗?

Question 1: What is the url I need to insert there? I guess it should be something like ssh://ssh-user@server-b.com:path-to-git-repos/project.git. Is that right?

问题2:由于连接到该URL的用户是GitLab的Git用户,我想我需要为此用户创建一个自己的SSH密钥并将公用密钥添加到我的Web服务器.由于Git用户无权执行任何操作(终端级别的Git命令除外),我该怎么办?我想我需要使用GitLab服务器的root用户来创建它,但是我该怎么做呢?当我以root用户身份连接时,我什至找不到Git用户的主目录.

Question 2: Since the user connecting to the url is GitLab's Git user, I guess I need to create an own SSH key for this user and add the public key to my web server. How can I do this since the Git user has no permissions to do anything except from Git commands on terminal level? I guess I need to create it with the root user of my GitLab server, but how do I do that? I can't even find the Git user's home dir when I'm connected as root.

推荐答案

ssh://ssh-user@server-b.com:path-to-git-repos/project.git是正确的URL.

由于连接到该URL的用户是GitLab的Git用户,所以我想我需要为此用户创建一个自己的SSH密钥并将公用密钥添加到我的Web服务器.

Since the user connecting to the url is GitLab's Git user, I guess I need to create an own SSH key for this user and add the public key to my web server.

是的,需要创建专用的私钥/公用ssh密钥对,而公用密钥对将进入serverB ~ssh-user/.ssh/authorized_keys:您可以自己复制它. 检查服务器A上的ps -eaf|grep gitlab:您将看到哪个帐户正在运行GitLab.
在帐户~/.ssh文件夹中创建您的SSH密钥.

Yes, a dedicated private/public ssh key pair needs to be created, with the public one going to serverB ~ssh-user/.ssh/authorized_keys: you can copy it yourself.
Check ps -eaf|grep gitlab on server A: you will see which account is running GitLab.
Creates your SSH keys in the account ~/.ssh folder.

根据评论,诀窍是:

  • 从根帐户生成ssh密钥对,然后将密钥移到~git/.ssh
  • ~git/.ssh/id_rsa.pub复制到serverB~ssh-user/.ssh/authorized_keys
  • 从根帐户测试ssh连接(因为git帐户仅限于GitLab命令)

  • to generate ssh key pairs from the root account, and move the keys to ~git/.ssh
  • to copy ~git/.ssh/id_rsa.pub over to serverB, ~ssh-user/.ssh/authorized_keys
  • to test the ssh connection from the root account (since the git account is limited to GitLab command)

ssh -i ~git/.ssh/id_rsa ssh-user@serverB

具有填充~root/.ssh/known_hosts文件的副作用,然后可以将其复制到~git/.ssh/known_hosts

That has the side effect to fill out the ~root/.ssh/known_hosts file, that can then be copied over to ~git/.ssh/known_hosts

  • 以使用SSH URL:

  • to use the SSH URL:

ssh://ssh-user@server-b.com/absolute/path-to-git-repos/project.git

并且镜像可以开始工作.

And the mirroring can start working.

这篇关于使用SSH连接到自己的Web服务器上的Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆