ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ssh免密访问对端服务

2020-03-21 20:00:35  阅读:218  来源: 互联网

标签:免密 对端 rsa 192.168 ssh key root id


ssh免密访问对端服务

主机名 主机IP 用途
ssh01 192.168.200.30 节点一
ssh02 192.168.200.31 节点二

1. root超级用户之前互相免密访问

#由节点一生产密匙
[root@ssh01 ~]# 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.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:                                     #直接回车确认
SHA256:EtqTFNuA6RHt84GS6k3akEOCJddF+mIdfYLvoUustdc root@ssh01
The key's randomart image is:                               #直接回车确认
+---[RSA 2048]----+
|   ..B=          |
|. o =..B         |
|.+ ..+*.+ .      |
|o . +*+=.o       |
| o o+.BoS.       |
|  =..o =..       |
| . B  = ..       |
|  o o+ o. E      |
|    . o.         |
+----[SHA256]-----+
#将节点一公钥id_rsa.pub文件复制到节点二的用户家目录下的.ssh目录下。如果对方没有.sh这个目录,就自己创建一个,但切记要把目录权限改成700
[root@ssh02 ~]# mkdir .ssh
[root@ssh02 ~]# chmod +700 .ssh
[root@ssh02 ~]# ll -la
#以上省略若干。。。
drwxr-xr-x   2 root root    6 3月  21 19:30 .ssh
#以下省略若干。。。

[root@ssh01 ~]# scp ./.ssh/id_rsa.pub root@192.168.200.58:~/.ssh/
ssh: connect to host 192.168.200.58 port 22: No route to host
lost connection
[root@ssh01 ~]# scp ./.ssh/id_rsa.pub root@192.168.200.31:~/.ssh/
root@192.168.200.31's password: 
id_rsa.pub                                                                   100%  392   536.7KB/s   00:00    
#将拷贝过去的id_rsa.pub文件里的内容追加到~/.ssh/authorized_keys文件当中
[root@ssh02 ~]# cd .ssh/
[root@ssh02 .ssh]# ll
总用量 4
-rw-r--r-- 1 root root 392 3月  21 19:31 id_rsa.pub
[root@ssh02 .ssh]# cat id_rsa.pub > authorized_keys
#实验测试
[root@ssh01 ~]# hostname -I
[root@ssh01 ~]# 192.168.200.30
[root@ssh01 ~]# ssh 192.168.200.31
Last login: Sat Mar 21 19:26:56 2020 from 192.168.200.1
[root@ssh02 ~]# hostname -I
[root@ssh02 ~]# 192.168.200.31

2. 非root普通用户之前互相免密访问

#由节点一生产密匙
[tomcat@ssh01 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tomcat/.ssh/id_rsa):  #直接回车确认
Enter passphrase (empty for no passphrase):                      #直接回车确认
Enter same passphrase again:                                     #直接回车确认
Your identification has been saved in /home/tomcat/.ssh/id_rsa.
Your public key has been saved in /home/tomcat/.ssh/id_rsa.pub.
The key fingerprint is:                                          #直接回车确认
SHA256:kiTqjtV8B+NS8WRwjj4fxk1BjexJpXd37K9LM6h0/2o tomcat@ssh01
The key's randomart image is:                                    #直接回车确认
+---[RSA 2048]----+
|      . .oo+.    |
|       =  +o.  . |
|    . + +oo.. . +|
|   . + B oo. . o.|
|  .   O S .     .|
| . o o B .   .  .|
|  o + o o . o + .|
| +   o . . o oE+ |
|. .       .  .=+.|
+----[SHA256]-----+
#将节点一公钥id_rsa.pub文件复制到节点二的用户家目录下的.ssh目录下。
[tomcat@ssh01 ~]$ ssh-copy-id -i /home/tomcat/.ssh/id_rsa.pub tomcat@192.168.200.31
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/tomcat/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
tomcat@192.168.200.31's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'tomcat@192.168.200.31'"
and check to make sure that only the key(s) you wanted were added.
#实验测试
[tomcat@ssh01 ~]$ hostname -I
192.168.200.30 
[tomcat@ssh01 ~]$ ssh 192.168.200.31
Last login: Sat Mar 21 19:43:40 2020 from 192.168.200.30
[tomcat@ssh02 ~]$ hostname -I
192.168.200.31 

标签:免密,对端,rsa,192.168,ssh,key,root,id
来源: https://www.cnblogs.com/ywb123/p/12541695.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有