两台linux密钥验证登陆

先关闭被登录的linux机器的selinux

临时关闭selinux: setenforce 0
永久关闭,编辑 /etc/selinux/config 把SELINUX=enforcing改为SELINUX=disabled 然后重启Linux

 

在A上执行:

[root@hyA ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):  #输入密码
Enter same passphrase again:  #再次输入密码
Your identification has been saved in /root/.ssh/id_rsa.  #私钥存放在本地即A/root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub.  #公钥存放在本地即A/root/.ssh/id_rsa.pub
The key fingerprint is:
a6:8b:41:74:dc:27:03:8c:9f:f6:5b:9d:b5:40:e2:f2 root@hyA
The key's randomart image is:
+--[ RSA 2048]----+
|     o.          |
|    ...o  . .    |
|    ..o.+..o     |
|   . .+ .+. . .  |
|    .. .So . + . |
|   .   o. E o .  |
|    . .  o       |
|     o ..        |
|    . .          |
+-----------------+

 

[root@hyA ~]# cat  .ssh/id_rsa.pub  #查看公钥
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtJRZnkzna4W/9ukd2CbTEYHzs4umy44kcpRv2KX6+/f5qujsW8VpJPPCdkz5G6wQAs8mGkuPZyWKRTsO8Am421lFumFXn+DayXE9I6yrgM58B/FLAJjs18vUWHuZKvqifX3bbnb7bL1/wde60WXmRr4bXOO2Phi+v9iosrvcpA9/OCoopItNssYhG1qkwD7c+Jjg+YqdXU4NuatuNppVUKC0U38xAt4kP0n5YGxewPcr8Z0gqEgE3ka3T3OVAsDQCLU+Fj00W9xq2+wb8yXeoVdIZoBRth6VylOJNR1rbnrmc7Vgj2e//6sRbhPEWFWMkhyhFAPKgYCqsJ5MBxIRWw== root@hyA

[root@hyB ~]# mkdir /root/.ssh
[root@hyB ~]# chmod 700 /root/.ssh
[root@hyB ~]# vi /root/.ssh/authorized_keys  #添加公钥
[root@hyB ~]# chmod 600 !$

 

[root@hyA ~]#yum -y install openssh-clients  #安装ssh

A上连接B

ssh root@hyB的ip

 

posted @ 2015-12-30 22:00  沐风先生  阅读(716)  评论(0)    收藏  举报