將B設定為bastion伺服器即可。具體請搜尋ssh proxy。
ssh user1@remote1 ‘ssh user2@remote2 “cat file”’ > file
用ssh作埠轉發即可
ssh -N -L 23333:C_ADDR:22 B_ADDR
scp -P 23333 local_file 127。0。0。1:/remote/path/
均在本地執行,B和C之間配好公鑰驗證
直接在b做a的埠轉發 socat 直接轉發tcp流量。或者在b上面搞個代理伺服器。
本地檔案 透過 A機 到 B機
scp -o ProxyCommand=‘ssh A -W %h:%p’ /tmp/a B:/tmp/a # B:/tmp/b 不存在則 /tmp/a -> B:/tmp/b,不然 /tmp/a -> B:/tmp/b/a
上面命令假設 A 可以免密碼登入 B,如果不是需要傳遞 authentication agent
eval $(ssh-agent)
ssh-add IDENTITY_FILE_TO_ACCESS_B
scp -o ProxyCommand=‘ssh -A A -W %h:%p’ /tmp/a B:/tmp/a
可以經過多個 jump server,本地檔案 透過 A機、B機 到 C機
scp -o ProxyCommand=‘ssh -A A ssh -A B -W %h:%p’ /tmp/a C:/tmp/a
另外,A機檔案 到 B機可以用 scp -3,較新的 openssh 帶
scp -pr3 A:/tmp/a B:/tmp/b
scp 有很多弊病
scp 選項通常帶 -p -r,保留 modification times, access times, and modes,遞迴複製,但依然無法保留 owner, group, acl, extended attributes 等,且時間戳精度為 秒
根據
How the SCP protocol works (Jan Pechanec‘s weblog)
時間戳精度最多到 毫秒
路徑末尾斜槓會被去除,不像 rsync 可以指定幾種語義
eval $(ssh-agent)
ssh-add IDENTITY_FILE_TO_ACCESS_B
rsync -a -e ’ssh -A A ssh‘ /tmp/a/ B:/tmp/b/
本地檔案 透過 A機、B機 到 C機
eval $(ssh-agent)
ssh-add IDENTITY_FILE_TO_ACCESS_B_AND_C
rsync -a -e ’ssh -A A ssh -A B‘ /tmp/a/ C:/tmp/b/