我有三台计算机,分别是家用计算机、工作计算机和服务器计算机,并且我通过以下方式从家用计算机连接到服务器:
ssh -t <WORKusername>@<WORK> ssh -p23456 <SERVERusername>@localhost
我需要将文件从 HOME 传输到 SERVER 但我无法将文件留在工作
此外我需要将文件从服务器传输到主目录处理完之后,该怎么办呢?
我已经看过了https://serverfault.com/questions/37629/how-do-i-do-multihop-scp-transfers和从我的(第三台)电脑在两个远程主机之间进行 scp但我无法更改 ssh 配置家机器
我已经尝试过这个,但毫无进展:
$ scp -o ProxyCommand="ssh <WORKusername>@<WORK> nc localhost" ASPEC.zip <SERVERusername>@localhost:~/
<WORKusername>@<WORK>'s password:
This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [hostname] [port[s]]
ssh_exchange_identification: Connection closed by remote host
lost connection
我也尝试了以下操作,但这是从服务器到主目录传输文件的反向操作:
ssh -t <WORKusername>@<WORK> "ssh -p 23456 <SERVERusername>@localhost \"cat file.zip\""
我也尝试过 tar,但是没有用:
tar c file.zip | ssh -t <WORKusername>@<WORK> "ssh -p 23456 <SERVERusername>@localhost | tar x"
Pseudo-terminal will not be allocated because stdin is not a terminal.
<WORKusername>@<WORK>'s password:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
然后我尝试:
# From home:
$ ssh -L 23456:<SERVERusername>@localhost:22 <WORKusername>@<WORK>
# After ssh, in WORK:
$ ssh -p 23456 <SERVERusername>@localhost
# From home:
$ scp -P file.zip <SERVERusername>@localhost:~/
当我给出 scp 命令时,我得到了这些错误,
# on WORK terminal:
channel 3: open failed: administratively prohibited: open failed
# on SERVER terminal:
ssh_exchange_identification: Connection closed by remote host
lost connection
我也尝试过 rsync,但是没有用:
rsync -e "ssh -A -t <WORKusername>@<WORK>e ssh -p23456 <SERVERusername>@localhost" file.zip :~/
我如何从家中使用 scp 将文件传输到服务器?
还有从服务器到主页吗?
答案1
尝试使用这个:
scp -P SERVERPORT -o 'ProxyCommand ssh -p WORKPORT WORKUSER@WORK nc %h %p 2>/dev/null' localfile SERVERUSER@SERVER:remotefile
ProxyCommand
在连接到 SERVER:SERVERPORT 的工作主机上创建代理(请参阅数控)。
%h
和%p
是 ssh 变量 - 分别是目标主机和端口。
答案2
您可以尝试以下方法:
cat localfile | ssh <WORKusername>@<WORK> "ssh -p23456 <SERVERusername>@localhost 'cat > remotefile'"