[Linux] 使用 rsync 加上 ssh key 與遠端 ssh server 傳送檔案

[Linux] 使用 rsync 加上 ssh key 與遠端 ssh server 傳送檔案

平常常用 scp 來傳檔案,如果 server 有用  key 的話,

加上 -i 參數也就可以了:

scp -i /home/testuser/mykey -r root@172.1.1.1:/tmp/atop_result ./

 

不過 scp 的問題就是沒有進度顯示,

不曉得現在到底複製到哪,還要等多久之類的…

這時可以用 rsync 加上 –progress 參數來一邊複製一邊顯示進度,

不過如果伺服器要用 ssh key 才能連上的話,要怎麼弄呢?

 

查了一下,Specify identity file (id_rsa) with rsync 這篇有人給了解答,

原來是用 -e 來指定 remote shell,key 的部分也在這邊指定就行了~

舉例來說:

testuser@localhost ~ $ rsync -rvz --progress -e 'ssh -i /home/testuser/mykey' root@172.1.1.1:/tmp/atop_result ./
The authenticity of host '172.1.1.1 (172.1.1.1)' can't be established.
DSA key fingerprint is 13:1a:1a:1c:14:18:11:10:1d:1f:19:10:11:19:17:18.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.1.1.1' (DSA) to the list of known hosts.
receiving file list ...
73 files to consider
atop_result/1.atop
58725418 100%   11.94MB/s    0:00:04 (xfer#1, to-check=71/73)
atop_result/2.atop
105197 100%  147.18kB/s    0:00:00 (xfer#2, to-check=70/73)

 

 

 

(本頁面已被瀏覽過 966 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料