Scp through ssh tunnel opened

假装没事ソ 提交于 2019-11-30 21:09:06

问题


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 

If I do:

scp file userserver@server.com:.

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

But if I do:

scp -P 2222 file userserver@localhost:. 

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

netstat | grep ssh | grep ESTABLISHED

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


回答1:


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


来源:https://stackoverflow.com/questions/33735624/scp-through-ssh-tunnel-opened

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!