2010年1月25日 星期一

Linux SSH自動登入

狀況:A主機想要SSH到B主機(192.168.1.4),自動登入無需輸入密碼

步驟如下:
1.在A主機

[root@www ~]# cd /root/.ssh
[root@www .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):
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:
8f:f7:45:87:a0:11:a2:a7:ec:88:45:e8:33:21:35:3f root@www.andowson.com

#產生兩個檔案:id_dsa和id_dsa.pub
[root@www .ssh]# ls -la
總計 24
drwx------ 2 root root 4096 11月 10 11:39 .
drwxr-x--- 7 root root 4096 10月 20 14:13 ..
-rw------- 1 root root 668 11月 10 11:39 id_dsa
-rw-r--r-- 1 root root 611 11月 10 11:39 id_dsa.pub
-rw-r--r-- 1 root root 2794 10月 9 22:41 known_hosts

#2.將id_dsa.pub傳到備份主機B的/root/.ssh目錄下
[root@www .ssh]# scp id_dsa.pub 192.168.1.4:/root/.ssh/id_dsa_XXX.pub
The authenticity of host '192.168.1.4 (192.168.1.4)' can't be established.
RSA key fingerprint is e2:61:f0:78:31:21:72:ce:06:dd:da:02:f1:41:05:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.4' (RSA) to the list of known hosts.
root@192.168.1.4's password:
id_dsa.pub 100% 611 0.6KB/s 00:00

3.將B主機的/root/.ssh/id_dsa_XXX.pub新增至/root/.ssh/authorized_keys
[root@www .ssh]# cat /root/.ssh/id_dsa_XXX.pub >> /root/.ssh/authorized_keys

沒有留言:

wibiya widget