码迷,mamicode.com
首页 > 其他好文 > 详细

centos 实现免密钥登陆

时间:2018-07-09 16:32:17      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:key   been   private   font   bee   ssh   size   公钥   auth   

1. 机器列表

    A:192.168.4.4

    B:192.168.4.5


    实现A免密钥登陆B


2.  A生成密钥对

[root@A ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:xfLhSq92OwFP30kH+K6QAQo1V38dTmjHdULaV66Zq8s root@A

The key's randomart image is:

+---[RSA 2048]----+

|     .o ...  o=o=|

|    .  o.. ..=+*+|

|     . ...+ +.+o+|

|      . .=o. .o=.|

|        S+o+ ++o |

|       . o= . +. |

|        . .o ..  |

|        ..o...   |

|       ....oE.   |

+----[SHA256]-----+

[root@A ~]# cd .ssh/

[root@A .ssh]# ls

id_rsa  id_rsa.pub

id_rsa : 生成的私钥文件 

id_rsa.pub : 生成的公钥文件 

know_hosts : 已知的主机公钥清单 

如果希望ssh公钥生效需满足至少下面两个条件: 

1) .ssh目录的权限必须是700 

2) .ssh/authorized_keys文件权限必须是600


3. 将生成的公钥scp到想要登陆的服务器 B,B服务器必须有 .ssh目录,如果没有就创建并授予700权限

[root@A .ssh]# scp -p ~/.ssh/id_rsa.pub root@192.168.4.5:/root/.ssh/authorized_keys

root@192.168.4.5's password:

id_rsa.pub


4. 验证

[root@A ~]# ssh 192.168.4.5

Last login: Thu Apr 19 10:32:54 2018 from 192.168.4.2


centos 实现免密钥登陆

标签:key   been   private   font   bee   ssh   size   公钥   auth   

原文地址:http://blog.51cto.com/calabash/2139296

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!