Friday, July 25, 2008

How to use ssh without password

1.首先在client上建立public Key和private key,需要使用ssh-keygen命令

[user_name@localhost .ssh]# ssh-keygen –t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/user_name/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 按enter
Enter same passphrase again: 按enter
Your identification has been saved in /user_name/.ssh/id_rsa.
Your public key has been saved in /user_name/.ssh/id_rsa.pub.
The key fingerprint is:
e8:8a:5e:ae:c7:13:45:d0:81:cd:3f:e6:1e:f8:88:5a
root@localhost.localdomain
#這樣會產生 id_rsa和id_rsa.pub 二個檔案:前者是private key後者是:public key.


2.然后将Private Key 放在client上的宿主目录, 一般放在/user_name/.ssh/目录中, 并修改权限为user可读


3 最后,将Public Key 放在任何一个您想登陆主机server中的某user的宿主目录下的.ssh/子目录人证文档中,
执行more id_rsa.pub >> authorized_keys即可。
scp id_rsa.pub username@server_hostname:~/.ssh/ #把id_rsa.pub 放到您要連線電腦的帳號中的.ssh

#注意 ~/.ssh 預設是沒有的,有二個方面可以產生 :第一種是手動建立. 並把目錄屬性更改為 700, 第二種是先用手動ssh到別的主機 ,第一次會有 認證的訊息出來按yes之後 .ssh的目錄就會自己產生了