您的位置:首页 > 其它

ssh免密码登陆

2016-03-13 22:54 295 查看
Ssh免密码登陆设置

准备工作:1.确保两个主机里没有id_rsa.pub和authorized_keys的文件(这两个文件会影响实验的结果)# find / -name id_rsa.pub可查看是否有这个文件。

2.两个主机已安装ssh # rpm -qa |grep openssh 可查看是否安装ssh的相关包

说明:A(192.168.1.106)B(192.168.1.11)

一、A主机执行ssh-keygen

[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:

75:06:e4:cb:25:67:5e:32:fb:9e:28:0a:24:09:18:aa root@lxh

The key's randomart image is:

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

|. .o |

|.o . . |

|o . + O . |

|. . . o X = |

|E o . S o o |

| o . |

| . . |

| . . o . |

| .. .. o |

+-----------------+

二、在B主机建立文件夹

[root@B~]# mkdir /root/.ssh

三、在A主机传送文件

[root@A ~]# scp /root/.ssh/id_rsa.pub root@192.168.1.111:/root/.ssh/authorized_keys

root@192.168.1.111's password:

id_rsa.pub

四、在A主机连接B主机

[root@A ~]# ssh root@192.168.1.111

Last login: Sun Mar 13 22:31:50 2016 from 192.168.1.106

[root@B ~]#

这样就不用输入密码成功连接到B主机了,输入exit退出B主机返回A主机。

[root@A ~]# ssh 192.168.1.111 ls

anaconda-ks.cfg

install.log

install.log.syslog

这样可以直接用B主机执行命令在A主机显示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: