当前位置:网站首页>SSH原理和公钥认证
SSH原理和公钥认证
2022-07-04 10:56:00 【星哥玩云】
建立过程
ssh利用rsa加密的不对称性,在两者之间分享一把只有他们两个人才知道的通信密钥,通过这个通信密钥,他们再进行之后的通信。
客户端接收服务端公钥,把自己产生的通信密钥加密发给服务端,服务端用私有密钥解密,此时两者采用对称密钥通信;
密钥和算法协商阶段
具体步骤如下:
(1)
服务器端和客户端分别发送算法协商报文给对端,报文中包含自己支持的公钥算法列表、加密算法列表、MAC(Message Authentication Code,消息验证码)算法列表、压缩算法列表等。
(2)
服务器端和客户端根据对端和本端支持的算法列表得出最终使用的算法。任何一种算法协商失败,都会导致服务器端和客户端的算法协商过程失败,服务器将断开与客户端的连接。
(3)
服务器端和客户端利用DH交换(Diffie-Hellman Exchange)算法、主机密钥对等参数,生成会话密钥和会话ID,并完成客户端对服务器身份的验证。
通过以上步骤,服务器端和客户端就取得了相同的会话密钥和会话ID。对于后续传输的数据,两端都会使用会话密钥进行加密和解密,保证了数据传送的安全。会话ID用来标识一个SSH连接,在认证阶段,会话ID还会用于两端的认证过程。
认证阶段
SSH提供两种认证方法:
1 password认证
利用AAA(Authentication、Authorization、Accounting,认证、授权和计费)对客户端身份进行认证。客户端向服务器发出password认证请求,将用户名和密码加密后发送给服务器;服务器将该信息解密后得到用户名和密码的明文,通过本地认证或远程认证验证用户名和密码的合法性,并返回认证成功或失败的消息。如果远程认证服务器要求用户进行二次密码认证,则会在发送给服务器端的认证回应消息中携带一个提示信息,该提示信息被服务器端透传给客户端,由客户端输出并要求用户再次输入一个指定类型的密码,当用户提交正确的密码并成功通过认证服务器的验证后,服务器端才会返回认证成功的消息。
2 publickey认证
采用数字签名的方法来认证客户端。目前,设备上可以利用RSA和DSA两种公钥算法实现数字签名。客户端发送包含用户名、公钥和公钥算法的publickey认证请求给服务器端。服务器对公钥进行合法性检查,如果不合法,则直接发送失败消息;否则,服务器利用数字签名对客户端进行认证,并返回认证成功或失败的消息。
第二种级别是基于密匙的安全验证
需要依靠密匙,也就是你必须为自己创建一对密匙,并把公用密匙放在需要访问的服务器上。如果你要连接到SSH服务器上,客户端软件就会向服务器发出请求,请求用你的密匙进行安全验证。服务器收到请求之后,先在该服务器上你的主目录下寻找你的公用密匙,然后把它和你发送过来的公用密匙进行比较。如果两个密匙一致,服务器就用公用密匙加密“质询”并把它发送给客户端软件。客户端软件收到“质询”之后就可以用你的私人密匙解密再把它发送给服务器。用这种方式,你必须知道自己密匙的口令。但是,与第一种级别相比,第二种级别不需要在网络上传送口令。第二种级别不仅加密所有传送的数据,而且“中间人”这种攻击方式也是不可能的(因为他没有你的私人密匙)。但是整个登录的过程可能需要10秒,但是相比输入密码的方式来说10秒也不长
ssh 的公钥认证就是使用了这一特性。服务器和客户端都各自拥有自己的公钥和密钥。为了说明方便,以下将使用这些符号。
Ac 客户端公钥
Bc 客户端密钥
As 服务器公钥
Bs 服务器密钥
在认证之前,客户端需要通过某种方法将公钥 Ac 登录到服务器上。
认证过程分为两个步骤:
1 会话密钥(session key)生成
客户端请求连接服务器,服务器将 As 发送给客户端。
服务器生成会话ID(session id),设为 p,发送给客户端。
客户端生成会话密钥(session key),设为 q,并计算 r = p xor q。
客户端将 r 用 As 进行加密,结果发送给服务器。
服务器用 Bs 进行解密,获得 r。
服务器进行 r xor p 的运算,获得 q。
至此服务器和客户端都知道了会话密钥q,以后的传输都将被 q 加密。
2 认证
服务器生成随机数 x,并用 Ac 加密后生成结果 S(x),发送给客户端
客户端使用 Bc 解密 S(x) 得到 x
客户端计算 q + x 的 md5 值 n(q+x),q为上一步得到的会话密钥
服务器计算 q + x 的 md5 值 m(q+x)
客户端将 n(q+x) 发送给服务器
服务器比较 m(q+x) 和 n(q+x),两者相同则认证成功
边栏推荐
- CAPL: on sysVar_ Update difference on sysvar
- Seven examples to understand the storage rules of shaped data on each bit
- Summary of several job scheduling problems
- The most ideal automated testing model, how to achieve layering of automated testing
- Jemeter script recording
- 2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
- [test theory] test process management
- Swagger and OpenAPI
- Application and Optimization Practice of redis in vivo push platform
- [Galaxy Kirin V10] [server] failed to start the network
猜你喜欢
XMIND installation
F12 clear the cookies of the corresponding web address
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Installation of ES plug-in in Google browser
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Basic data types of MySQL
[Galaxy Kirin V10] [server] soft RAID configuration
From programmers to large-scale distributed architects, where are you (I)
随机推荐
Linked list operation can never change without its roots
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
Fundamentals of database operation
TS type gymnastics: illustrating a complex advanced type
Canoe - the third simulation project - bus simulation - 3-2 project implementation
Recursive method to achieve full permutation (C language)
Four characteristics and isolation levels of database transactions
[Galaxy Kirin V10] [desktop] FTP common scene setup
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
Learning XML DOM -- a typical model for parsing XML documents
How do microservices aggregate API documents? This wave of show~
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
[test theory] test phase analysis (unit, integration, system test)
Time complexity and space complexity
Elevator dispatching (pairing project) ④
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
regular expression
DDL language of MySQL database: create, modify alter, delete drop of databases and tables
[Galaxy Kirin V10] [server] soft RAID configuration