Linux之间创建SSH互信

发布 : 2019-04-13 分类 : Linux 浏览 :

实验环境

本文基于Oracle Linux 5.5搭建
Machine 1: 10.190.104.39
Machine 2: 10.190.104.40

实验目的

通过创建SSH互信,当machine 1上的oracle用户需要访问machine 2时,不需要输入密码,反之亦然

在Machine 1上创建互信

建文件夹

如存放ssh-key的文件夹不在,首先需要手动建立一下

1
mkdir -p ~/.ssh/id_rsa

创建SSH-KEY

1
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
name value comments
-t rsa 指定编码类型,此例中是rsa
-P 密码,此例中为空
-f ~/.ssh/id_rsa 指定生成的文件

生成的id_rsa是公匙,id_rsa.pub是公匙

1
2
3
4
5
6
[oracle@edsir71p9 ~]$ ll ~/.ssh/
total 16
-rwxr-xr-x 1 oracle oinstall 399 Apr 7 00:05 authorized_keys
-r-------- 1 oracle oinstall 1675 Apr 7 00:00 id_rsa
-rwxr-xr-x 1 oracle oinstall 398 Apr 7 00:00 id_rsa.pub
-rwxr-xr-x 1 oracle oinstall 406 Apr 7 00:02 known_hosts

在Machine 2上创建互信

Machine 2同理,再来一遍

Troubleshooting

如果ssh时遇到下面问题

1
2
3
4
5
6
7
8
9
[oracle@edsir71p9 Skillset]$ ssh edsir71p10
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0775 for '/home/oracle/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/oracle/.ssh/id_rsa
Enter passphrase for key '/home/oracle/.ssh/id_rsa':

只需将/home/oracle/.ssh/id_rsa的权限改为400即可

1
chmod -R 400 /home/oracle/.ssh/id_rsa

本文作者 : Shen Peng
原文链接 : http://yoursite.com/2019/04/13/Linux之间创建SSH互信/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹