Client Host:
Server Host: 1. 在client host 端生成一个rsa密钥代码:
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/abc/.ssh/id_rsa): ------> 回车默认 Enter passphrase (empty for no passphrase): ------> 回车默认 Enter same passphrase again: ------> 回车默认 Your identification has been saved in /home/abc/.ssh/id_rsa. Your public key has been saved in /home/abc/.ssh/id_rsa.pub. The key fingerprint is: 71:89:9e:56:de:23:83:6a:9e:b8:96:15:f3:57:cb:b4 abc@i965 The key's randomart image is: +--[ RSA 2048]----+ | | | . . | | o + | | o. B .o | | +S ++oo | | .o. .oE. | | oo . | | o+ . | | .o.o | +-----------------+
注意:如果原来已经生成过,则可以直接使用,不需要再生成一次;而且也不推荐,否则以前设置的免认证host可能就得重新设置了.
2. 将生成的id_rsa.pub通过scp上传到Server Host端:代码:
~$ scp .ssh/id_rsa.pub abc@192.168.1.101:/home/abc
a) 如果Server Host端不存在 /home/abc/.ssh/authorized_keys文件,则直接将上传的文件重命名即可:
代码:
~$ mv id_rsa.pub .ssh/authorized_keys
b) 如果Server Host端已经存在 /home/abc/.ssh/authorized_keys文件,将上传文件的内容附加上即可:
代码:
~$ cat id_rsa.pub >> .ssh/authorized_keys
3. 退出Server Host,然后再在Client Host上ssh登录,就不在需要密码认证了。