需求:

    hostA 要免密码ssh登入 hostB,即建立ssh信任关系


实施:

    1、hostA:在~/.ssh,创建ssh密钥对

            执行命令 ssh-keygen -t rsa (要求输入的位置直接回车),默认生成密钥对文件 id_rsa 和 id_rsa.pub 

    2、hostB:在~/.ssh,修改信任文件authorized_keys

            把 hostA 的公钥文件 id_rsa.pub 追加到 hostB 的~/.ssh/authorized_keys文件中


验证:

    hostA 要免密码ssh登入 hostB


小结:

    我要免密码登陆你,把我的公钥给你


可能发生的意外和解决办法:

    建立了信任关系,但是仍然无法通过信任关系登陆,检查:

        1、文件权限是否正确(实践证明这点是有用的)

            SSH doesn’t like it if your home or ~/.ssh directories have group write permissions. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600

            You can also get around this by adding StrictModes off to your ssh_config file, but I’d advise against it - fixing permissions is the way to Go

        2、确保sshd服务已开启

        3、跟ssh配置文件有关/etc/ssh/sshd_config(未经实践)

            据说可以修改ssh服务的认证方法 ,从密码认证改为公钥认证,请自行百度“/etc/ssh/sshd_config 信任关系