星期五, 1月 23, 2009

scp + ssh 免登入密碼就可以做檔案傳輸

今天要找一個解決方案,因為我要傳檔案到我其中一個 server ,但是我想讓他可以自動作業,可是又避免不了要輸入登入密碼
把密碼寫在shell也是很笨
所以找到了以下的解決方案

以下內容是從這裡來的 http://dz.adj.idv.tw/thread-48-1-4.html
 
1.完成單向Trusted SSH Authorized


要 A (10.0.0.1) 要對 B (192.168.0.1) 做異地備援 ...所以我針對 A 讓它使用SSH連到 B
時...不需要輸入密碼...User 是 Root...SSH
Version2的版本..首先要先在A(10.0.0.1)產生public/private dsa key pair..





[root@mondeo home]# cd /root/.ssh/
[root@mondeo .ssh]# ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase): <-- 此處不打passphrase..下次才不會詢問password
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
11:22:33:44:55:66:77:88:99:00:11:22:33:44:55:66
root@mondeo.adj.idv.tw
[root@mondeo .ssh]#

這時會在系統下看到兩個檔案...id_dsa與id_dsa.pub 現在要把id_dsa.pub丟到192.168.0.1 並且更名為 authorized_keys2





[root@mondeo .ssh]# scp id_dsa.pub 192.168.0.1:/root/.ssh/authorized_keys2
root@192.168.0.1's password:
id_dsa.pub 100% |***************************************************************************| 612 00:00
[root@mondeo .ssh]#


現在您可以執行ssh 192.168.0.1 看看能否登入而不需要輸入密碼...

沒有留言:

張貼留言

Powered By Blogger