1 ssh之间如何免密码 互信任关系 ---原理是 私钥加密公钥解密
实验 web1 (192.168.204.7)与 web2(192.168.204.9) 之间建立ssh 互信任关系
涉及命令 ssh-keygen 生成公钥和私钥
操作web1上
1 自动化命令
ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa
-t 指定类型
-P 指定密码
-f 指定文件
结果:
私钥保存至 id_rsa 公钥保存至 id_rsa.pub
[[email protected] ~]# ls .ssh/
id_rsa id_rsa.pub
2 安装公钥在远程主机上
ssh-copy-id [-i [identity_file]] [[email protected]]machine
ssh-copy-id -i .ssh/id_rsa.pub [email protected]
结果: web2 上记录了 认证信息
[[email protected] ~]# cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAlbP1N67oiA59fmNb7G3HVezISWn4yrwWEjPgh4zMLvhuhi3riG9Sa1UyNaY26+WmK3/hj7UMrZlCdEsbszh0ElGHcWsfc2U1gcFH5ga7qkbWhrXKDYgs3zvlAxNvqdcfSyP4fo3wiDRDdpHbhVkNGvpQ8TJA0Tp+zflM7SJpJdB2tHfNOxTeRHTRqJ3gO5FQOoWBWXJny7oACHvVrt8KbpkHTcu81re9Hlwf590Ue86tgwdxTU8QemNMZa1PGVktOHdnpZ4jeq7rYKysRH+QGqNcHKmUtFEIxguVCm+k+iLHApQRf6mUn+gJxYBQaBLH403IOD0fyP57vSu6Wfg+1w== [email protected]
[[email protected] ~]# ls -l .ssh/authorized_keys
在web2 上操作同样的操作 即可实现互信