ssh有一套很有用的工具,其中的ssh-keygen可以用来生成private和public密钥文件.将生成的public密钥文件内容拷贝到远程机器的authorized_keys文件后,可以使ssh到另外一台机器的登陆不用密码.具体方法如下.
1) 在本地机器中的~/.ssh/目录下执行下命令,
ssh-keygen -t dsa 或者ssh-keygen -t rsa
将生成两个文件,id_dsa和id_dsa.pub. 或者 id_rsa和id_rsa.pub
2) 将公钥文件id_dsa.pub或者id_rsa.pub的内容添加到远程机器的~/.ssh/authorized_keys文件中.
A、在各hostname01和hostname02和hostname03上运行/usr/bin/ssh-keygen -t dsa
B、ssh hostname01 "cat ~/.ssh/ id_dsa.pub" >>~/.ssh/authorized_keys(引号内才为远程命令)
ssh hostname02 "cat ~/.ssh/ id_dsa.pub" >>~/.ssh/authorized_keys(所有内容都添加到本地文件authorized_keys内)
ssh hostname03 "cat ~/.ssh/ id_dsa.pub" >>~/.ssh/authorized_keys
C、scp ~/.ssh/authorized_keys oracle@hostname01:/home/oracle/.ssh/
scp ~/.ssh/authorized_keys oracle@hostname02:/home/oracle/.ssh/
scp ~/.ssh/authorized_keys oracle@hostname02:/home/oracle/.ssh/
注意:目录.ssh和文件authorized_keys的权限必须是600