scp 通过 ssh 隧道打开

编程入门 行业动态 更新时间:2024-10-27 00:30:38
本文介绍了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

如果我这样做:

scp file userserver@server:.

然后 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 隧道打开

本文发布于:2023-10-07 12:39:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:隧道   scp   ssh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!