远程管理SSH服务免密登录解决方案

SSH两种认证⽅式

1、基于⽤户名密码的认证(精简版)

JumpServer => ssh code@RealServer的IP地址

2、基于密钥对的认证 基于密钥对认证,也就是所谓的免密码登录,理解免密登录原理:

任 务 解 决 ⽅ 案

1 . 跳 板 机 上 的 开 发 ⼈ 员 ⾃ ⼰ ⽣ 成 ⼀ 对 秘 钥 c o d e 1 为 例 :

[ c o d e 1 @ M i s s H o u ~ ] $ s s h - k e y g e n

G e n e r a t i n g p u b l i c / p r i v a t e r s a k e y p a i r .

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

Enter passphrase (empty for no passphrase): Enter same passphrase again:

Your identification has been saved in /home/code1/.ssh/id_rsa.

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

The key fingerprint is:

14:78:f6:70:9f:48:64:7e:19:c3:cb:c3:7a:52:1e:d8 code1@MissHou.itcast.cc

The key's randomart image is: +--[ RSA 2048]----+

|       ...o.o    |

|      . ++o .+   |

|       o.=.Boo   |

|       .  +.E    |

|        S  + o   |

|          o o    |

|           o     |

|                 |

|                 | +-----------------+

[code1@MissHou ~]$ ll -a .ssh/

total 16 drwx------ 2 code1 coding 4096 Dec 28 09:33 .

drwx------ 5 code1 coding 4096 Dec 27 11:49 .

. -rw------- 1 code1 coding 1675 Dec 28 09:33

id_rsa -rw-r--r-- 1 code1 coding  405 Dec 28 09:33 id_rsa.pub

2. 将code1⽤户的公钥远程拷⻉到⽣产服务器上指定⽤户的指定⽬录

[code1@MissHou ~]$ ssh-copy-id code@10.1.1.1

The authenticity of host '10.1.1.1 (10.1.1.1)' can't be established.

RSA key fingerprint is 30:c8:1a:67:55:22:33:26:e5:fb:44:56:4d:8b:26:40.

Are you sure you want to continue connecting (yes/no)?

yes Warning:

Permanently added '10.1.1.1' (RSA) to the list of known hosts.

code@10.1.1.1's password: Now try logging into the machine, with "ssh 'code@10.1.1.1'", and check in:扩展总结 图解SSH加密算法 des 对称的公钥加密算法,安全低,数据传输速度快;

使⽤同⼀个秘钥进⾏加密或解密 rsa ⾮对称的公钥加密算法,安全,数据传输速度慢 ,SSH默认的加密算法 思考1: ⽤户信息加密了,但如何安全的保存密钥呢?

 .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. 或者 [code1@MissHou ~]$ scp -P22 ~/.ssh/id_rsa.pub code@10.1.1.1:/home/code/.ssh/authorized_keys code@10.1.1.1's password: id_rsa.pub                              

3. 测试验证 [code1@MissHou ~]$ ssh -lcode 10.1.1.1 Last login: Fri Dec 28 09:38:17 2018 from 10.1.1.250 [code@server ~]$

1、远程Server收到Client端⽤户的登录请求后,Server端把⾃⼰的公钥发给⽤户

2、Client端使⽤这个公钥,将密码进⾏加密

3、Client将加密的密码发送给Server端

4、远程Server⽤⾃⼰的私钥,解密登录密码,然后验证其合法性

5、根据验证结果,给Client相应的响应。 思考2: ⾮对称加密就绝对安全吗?

问题: SSH中是如何解决这个问题的呢? 答:基于⽤户名密码认证和密钥对认证。 ==基于⽤户密码的认证== 提示信息:⽆法确认主机192.168.10.171的真实性,指纹 是 9f:71:de:3c:86:25:dd:f0:06:78:ab:ba:96:5a:e4:95. ,你确定想要继续吗?

[root@MissHou ~]# ssh 192.168.10.171 The authenticity of host '192.168.10.171 (192.168.10.171)' can't be established. RSA key fingerprint is 9f:71:de:3c:86:25:dd:f0:06:78:ab:ba:96:5a:e4:95.

Are you sure you want to continue connecting (yes/no)?说明:

1. 理论上应该是对公钥的确认,由于公钥通过RSA算法加密,太⻓,不好直接⽐较,所以给 公钥⽣成⼀个hash的指纹,⽅便⽐较。

2. 当客户端输⼊yes确认对⽅的公钥指纹后,server端的公钥就会被存放到客户机的⽤户家 ⽬录⾥~/.ssh/known_hosts⽂件中,下次再访问就直接通过密码登录,不需要再确认公 钥。 ==基于秘钥对的认证(免密码登录)==   相关⽂件解读: 1. id_rsa:保存私钥 2. id_rsa.pub:保存公钥

3. authorized_keys:保存已授权的客户端公钥 4. known_hosts:保存已认证的远程主机公钥

扩展总结

图解SSH加密算法

des 对称的公钥加密算法,安全低,数据传输速度快;使⽤同⼀个秘钥进⾏加密或解密

rsa ⾮对称的公钥加密算法,安全,数据传输速度慢 ,SSH默认的加密算法

1、远程Server收到Client端⽤户的登录请求后,Server端把⾃⼰的公钥发给⽤户

2、Client端使⽤这个公钥,将密码进⾏加密

3、Client将加密的密码发送给Server端

4、远程Server⽤⾃⼰的私钥,解密登录密码,然后验证其合法性 5、根据验证结果,给Client相应的响应。

思考2: ⾮对称加密就绝对安全吗?

问题: SSH中是如何解决这个问题的呢? 答:基于⽤户名密码认证和密钥对认证。 ==基于⽤户密码的认证==

提示信息:⽆法确认主机192.168.10.171的真实性,指纹 是 9f:71:de:3c:86:25:dd:f0:06:78:ab:ba:96:5a:e4:95. ,你确定想要继续吗?

[root@MissHou ~]# ssh 192.168.10.171 The authenticity of host '192.168.10.171 (192.168.10.171)' can't be established. RSA key fingerprint is 9f:71:de:3c:86:25:dd:f0:06:78:ab:ba:96:5a:e4:95. Are you sure you want to continue connecting (yes/no)?

说明: 1. 理论上应该是对公钥的确认,由于公钥通过RSA算法加密,太⻓,不好直接⽐较,所以给 公钥⽣成⼀个hash的指纹,⽅便⽐较。 2. 当客户端输⼊yes确认对⽅的公钥指纹后,server端的公钥就会被存放到客户机的⽤户家 ⽬录⾥~/.ssh/known_hosts⽂件中,下次再访问就直接通过密码登录,不需要再确认公 钥。 ==基于秘钥对的认证(免密码登录)==

相关⽂件解读:

1. id_rsa:保存私钥

2. id_rsa.pub:保存公钥

3. authorized_keys:保存已授权的客户端公钥

4. known_hosts:保存已认证的远程主机公钥

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值