使用scp在Linux主機之間進行定時備份
一、scp在建立連線中是需要密碼認證的,所以我們第一步就是新增ssh公匙。
ssh終端執行
結果如下
Generating public/private rsa key pair.
Enter file in which to save the key (/home/.username/ssh/id_rsa):#回車
Enter passphrase (empty for no passphrase):#回車
Enter same passphrase again:#回車
Your identification has been saved in /home/.username /.ssh/id_rsa.
Your public key has been saved in /home/.username /.ssh/id_rsa.pub.
The key fingerprint is:
38:25:c1:4d:5d:d3:89:bb:46:67:bf:52:af:c3:17:0c [email protected]
Generating RSA keys:
Key generation complete.
會在使用者目錄~/.ssh/產生兩個檔案,id_rsa,id_rsa.pub
第二是把本地(10.1.1.1)主機上的id_rsa.pub檔案拷貝到遠端linux(10.1.1.2)主機的root使用者主目錄下的.ssh目錄下,並且改名為authorized_keys
即:
這樣在本地linux(10.1.1.1)主機上使用scp命令複製檔案到遠端linux主機(10.1.1.2)上將不提示輸入密碼了,直接複製了。反之亦然!
二、把命令放入指令碼,如以下的指令碼事例(請根據自己的具體情況修改)
