简体   繁体   English

如何通过 SSH 访问远程(远程服务器上的本地 gitlab 实例)存储库?

[英]How do I access a remote (local gitlab instance on remote server) repository over SSH?

The setup is as follows:设置如下:

  • remote private server far far away遥远的私人服务器
  • remote private server has private gitlab instance on port XXXX远程私有服务器在端口 XXXX 上有私有 gitlab 实例
  • remote private server is configured to allow SSH sign-on via SSH key远程私有服务器配置为允许通过 SSH 密钥登录
  • gitlab instance on port XXXX of remote private server requires SSH key authentication using different SSH key远程私有服务器 XXXX 端口上的 gitlab 实例需要使用不同的 SSH 密钥进行 SSH 密钥认证

How can I clone that repository onto my local machine, and push/pull data remotely given that setup?我如何将该存储库克隆到我的本地机器上,并根据该设置远程推/拉数据?

This is how I access it locally when I am not far, far away from remote private server:当我离远程私有服务器不远很远时,我是这样在本地访问它的:

git clone git@XXX.XXX.XX.X:REPODIR/repo_name.git

In this case, XXX.XXX.XX.X is the IP of the local git-lab instance on the remote network.在这种情况下,XXX.XXX.XX.X 是远程网络上本地 git-lab 实例的 IP。

Is there anyway to tunnel into the remote network and access the gitlab instance by proxy (forgive me for using the word wrong likely).反正有没有隧道进入远程网络并通过代理访问gitlab实例(原谅我可能使用错误的词)。

Thank you.谢谢你。

Ok, mostly thanks to @o11c for this, although here are my findings that led me to be able to clone my repo remotely.好的,主要感谢@o11c,尽管这是我的发现,使我能够远程克隆我的 repo。

Disclaimer: ProxyJump (-J see ssh manpage) is the shorthand, more modern, version of this but I couldn't get it working -- if anyone wants to update with their implementation of ProxyJump that would be useful!免责声明:ProxyJump(-J 请参阅 ssh 联机帮助页)是它的简写、更现代的版本,但我无法使其正常工作——如果有人想更新他们的 ProxyJump 实现,那将是有用的!

SSH into your remote account to the main server with port to your gitlab or other application instance, using your main identity (this can be in ~/.ssh or you can manually reference it with -i)使用您的主要身份(这可以在 ~/.ssh 中,或者您可以使用 -i 手动引用它)通过 SSH 到您的远程帐户到主服务器,并使用您的 gitlab 或其他应用程序实例的端口

ssh -ND 3131 nkunes@XXX.XXX.1.146 -i ../../keys/XXX-ssh &

I then source this bash script in the shell I intend to run git commands (notice the ProxyCommand usage instead of ProxyJump, this is the old method of doing this yet it works well for me. also notice the 127.0.0.1:PORT should be swapped with your application's port)然后我在我打算运行 git 命令的 shell 中获取这个 bash 脚本(注意 ProxyCommand 的用法而不是 ProxyJump,这是执行此操作的旧方法,但它对我来说效果很好。还要注意 127.0.0.1:PORT 应该被交换与您的应用程序的端口)

alias ssh="ssh -o ProxyCommand='/usr/bin/nc -X 4 -x 127.0.0.1:3131 %h %p'"
export GIT_SSH=~/Desktop/XXX-eng/ssh-access/ssh-proxy.sh
export PRE_SSH_ALIAS_PROMPT="$PS1"
export PS1="<< SSH ALIAS >>$PS1"

Where ssh-proxy.sh is defined as follows: (again, swap the port out for your application, and possibly use ProxyJump if want modern implementation)其中ssh-proxy.sh定义如下:(同样,为您的应用程序交换端口,如果需要现代实现,可能使用 ProxyJump)

ssh -o ProxyCommand='/usr/bin/nc -X 4 -x 127.0.0.1:3131 %h %p' "$@"

Then, you can clone normally using:然后,您可以使用以下命令正常克隆:

git clone git@XXX.XXX.XX.X:REPODIR/repo_name.git

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Subversion over ssh - 从Windows主机访问Linux上的远程存储库 - Subversion over ssh - access to the remote repository on Linux from Windows host 如何正确地将本地存储库上的远程设置为我在服务器上的集中存储库? - How correctly set the remote on a local repository to my centralized repository on a server? 当我使用 ssh 到远程服务器以 git 存储库时如何获取过程? - How to get the process when I use ssh to a remote server to git a repository? 如何使用 ssh 将远程服务器变量存储到本地服务器变量? - How can I store a remote server variable to local server variable with ssh? 如何使用 nohup 通过 ssh 在远程服务器上执行本地 bash 脚本 - How to execute a local bash script on remote server via ssh with nohup 如何通过创建不通过SSH的目录将文件从本地服务器复制到远程服务器? - How can I copy file from local server to remote with creating directories which absent via SSH? 在 Python 中,如果用户通过 SSH 连接,我如何获取用户的远程 IP(他们的最后一跳)? - In Python, how do I get user's remote IP (their last hop) if they're connected over SSH? 如何设置对Blazegraph服务器的远程访问? - How do I set up remote access to a Blazegraph server? 远程 SSH 与本地服务器下载不工作 - Remote SSH with Local Server Download not working 如何使用 sed 通过 ssh 修改远程文件? - How can i modify a remote file over ssh with sed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM