Eri*_* B. 10 ssh ssh-tunneling port-forwarding
有没有办法在单个 SSH 命令中通过 SSH 登录到通过中间服务器的远程服务器?本质上,我需要创建一个到我的“桥接服务器”的隧道,并通过该隧道登录到远程服务器。
例如,我试图将以下内容压缩到一个 ssh 命令中:
这目前有效,但我宁愿能够将所有内容压缩到一个命令中,这样如果我退出我的 ssh shell,我的隧道就会同时关闭。
我在我的配置中尝试了以下但无济于事:
Host axp
User remote_userid
HostName remoteserver.com
IdentityFile ~/.ssh/id_rsa.eric
ProxyCommand ssh -W %h:%p bridge_userid@bridgemachine.com
Run Code Online (Sandbox Code Playgroud)
根据@jasonwryan 的评论和透明多路链接,我可以使用以下命令:
ssh -A -t bridge_userid@bridgemachine.com ssh -A remote_userid@remoteserver.com
Run Code Online (Sandbox Code Playgroud)
但现在我想把它整齐地打包到我的 .ssh/config 文件中,并且不太确定我需要使用什么作为我的 ProxyCommand。我在网上看到了几个链接以及@boomshadow 的回答nc,但不幸的是,我用作桥接机的 AIX 服务器上没有安装 netcat。
小智 9
ProxyCommand 正是您所需要的。在我公司,所有 DevOps 技术人员都必须使用“跳转站”才能访问 VPC 的其余部分。Jumpstation 是受 VPN 访问控制的。
我们的 SSH 配置设置可以自动通过 Jumpstation。
这是我的 .ssh/config 文件的编辑版本:
Host *.internal.company.com
User jacob
IdentityFile ~/.ssh/id_rsa
ProxyCommand ssh -q -A jacob@company-internal-jumphost nc -q0 %h %p
Run Code Online (Sandbox Code Playgroud)
每次我对该“内部”子域上的服务器执行“ssh”操作时,它都会首先自动跳过 jumpstation。
编辑:这是“内部”VPC 的 .ssh/config的整个部分,供我们登录:
# Internal VPC
Host company-internal-jumphost
Hostname 10.210.x.x #(edited out IP for security)
IdentityFile ~/.ssh/id_rsa
Host 10.210.*
User ubuntu
IdentityFile ~/.ssh/company-id_rsa
ProxyCommand ssh -q -A jacob@company-internal-jumphost nc -q0 %h %p
Host *.internal.company.com
User jacob
IdentityFile ~/.ssh/id_rsa
ProxyCommand ssh -q -A jacob@company-internal-jumphost nc -q0 %h %p
Run Code Online (Sandbox Code Playgroud)
如果使用 OpenSSH 7.3 或更高版本,那么您可以ProxyJump像这样使用:
$ ssh -o ProxyJump=user1@gateway user2@remote
Run Code Online (Sandbox Code Playgroud)
如果省略任一用户,则隐含本地用户。
间接登录主题的一个变体是间接文件传输。您可以使用scp和rsync间接ssh通过中间服务器复制文件。
使用scp以下方法通过网关进行复制:
$ scp -oProxyJump=root@gateway myfile user@remote:path
Run Code Online (Sandbox Code Playgroud)
如果user省略,则使用本地用户。
将ProxyJump在OpenSSH的7.3推出。另一种方法是使用ProxyCommand:
$ scp -oProxyCommand="ssh -W %h:%p root@gateway" myfile user@remote:path
Run Code Online (Sandbox Code Playgroud)
使用rsync以下方法通过网关进行复制:
$ rsync -av -e 'ssh -o "ProxyJump root@gateway"' myfile user@remote@path
Run Code Online (Sandbox Code Playgroud)
或者
$ rsync -av -e 'ssh -o "ProxyCommand ssh -A root@gateway -W %h:%p"' myfile user@remote@path
Run Code Online (Sandbox Code Playgroud)
我更详细地解释了其他答案(关于超级用户),这些答案涵盖了间接scp和间接rsync。
| 归档时间: |
|
| 查看次数: |
16674 次 |
| 最近记录: |