scp 通过 ssh 隧道打开 [英] Scp through ssh tunnel opened

查看:121
本文介绍了scp 通过 ssh 隧道打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 machineA 发送文件,该机器已与服务器打开反向隧道.反向隧道将 machineA 上的 22 端口与服务器上的 2222 端口连接起来:

I want to send files from machineA which has opened a reverse tunnel with a server. The reverse tunnel connects port 22 on machineA with port 2222 on the server:

autossh -M 0 -q -f -N -o "ServerAliveInterval 120" -o "ServerAliveCountMax 1" -R 2222:localhost:22 userserver@server.com 

如果我这样做:

scp file userserver@server.com:.

然后 SCP 通过 SSH 发送带有新登录名的文件,在我的情况下使用公钥/私钥.

then SCP sends the file with a new login over SSH, in my case using public/private key.

但如果我这样做:

scp -P 2222 file userserver@localhost:. 

我收到连接被拒绝"消息.如果我将上面的 2222 替换为找到的端口,也会发生同样的情况:

I get a "connection refused" message. The same happens if I replace 2222 above with the port found with:

netstat | grep ssh | grep ESTABLISHED

如何在不打开新 ssh 连接的情况下发送文件(无需握手)?

How I can send files without opening a new ssh connection (without handshake)?

推荐答案

您可以在 ssh_config (~/.ssh/config),这将为进一步的 ssh/scp/sftp 会话创建持久连接.很简单:

You can use ControlMaster option in your ssh_config (~/.ssh/config), which will create persistent connection for further ssh/scp/sftp sessions. It is easy as pie:

Host yourhost
  Hostname fqdn.tld
  Port port_number # if required, but probably yes, if you do port-forwarding
  ControlMaster auto
  ControlPath ~/.ssh/master-%r@%h
  ControlPersist 5m

这篇关于scp 通过 ssh 隧道打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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