[英]How do I access a remote (local gitlab instance on remote server) repository over SSH?
The setup is as follows:设置如下:
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.