如何在ssh会话中执行scp命令?

时间:2018-07-25 10:10:48

标签: bash sh

在通过SSH连接时如何复制位于本地文件夹中的文件?

此命令可以完美运行,但仅当我在本地运行时才能使用:

scp /home/josh/Desktop/DATA/import/file001.csv root@10.0.3.14:/var/www/html/project

我希望通过ssh连接来启动它具有相同的结果,这可能吗?

2 个答案:

答案 0 :(得分:2)

您可以在.ssh/config

中设置ControlMaster
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r

然后使用ssh命令模式,它将重用现有的连接:

将ssh会话推入后台的解决方案:

local$ ssh remote
remote$ ~^Z                   # Shift+`, Ctrl+z   - Push ssh into background
local$ scp file remote:/remotepath
local$ fg
remote$

您还可以通过以下方式打开隧道:

remote$ ~C                     # Shift+`, Shift+c  - Enter command mode
ssh> -R15000:localhost:22      # tunnel to local:22 from remote:15000
 Forwarding port.
remote$ scp -P15000 localhost:/filepath ~/
remote$ ~C
ssh> -KR15000
 Canceled forwarding.
remote$

答案 1 :(得分:0)

步骤1:获取IP地址

hostname -I

第2步:将SCP调用到SSH

 scp josh@my_ip_address:~/Desktop/DATA/import/file001.csv  /var/www/html/project

ie :“ josh ”是我连接到PC的名称

相关问题