SSH key management method, device, equipment and storage medium

By setting the validity period of the public key in SSH key management and automatically deleting expired keys, the problems of cumbersome and incorrect deletion of key pairs in the prior art are solved, and precise control and flexibility are improved.

CN114337989BActive Publication Date: 2024-11-12DAWNING INT INFORMATION IND CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111657322.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-30
Publication Date
2024-11-12
Estimated Expiration
2041-12-30

AI Technical Summary

Technical Problem

It is difficult to set the validity period for the management of existing SSH keys, resulting in high risk of key pair leakage, and manual operations are cumbersome and easy to delete mistakes, making it impossible to achieve minute-level validity period control.

Method used

Set the validity period when configuring the public key, and automatically delete the expired public key through the server. Use the MD5 value as the identifier and store it in the authorized_keys file and external media to achieve automated expired public key deletion.

Benefits of technology

It reduces the labor demand for manually configuring key pairs, avoids the risk of mistaken deletion, and realizes the precise setting of the validity period of the key pair, improving the flexibility and usage scenarios of the key pair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114337989B_ABST
    Figure CN114337989B_ABST
Patent Text Reader

Abstract

The present invention discloses a management method, device, equipment and storage medium of SSH key, the method comprising: the server to be accessed obtains a public key; the information of the public key is stored in the authorized_keys file of the server to be accessed; the server to be accessed stores the information of the public key; wherein the information of the public key includes validity period information; the server to be accessed obtains the information of the expired public key according to the validity period information; the server to be accessed deletes the expired public key. The technical scheme of the present invention can set the validity period of the public key while configuring the public key according to actual needs, and can automatically delete the expired public key; on the one hand, it reduces the manpower requirements for manually configuring key pairs and reduces failures caused by human errors; on the other hand, it can accurately set the validity period of the key pair, improve the flexibility of key pair configuration, and increase the use scenarios of the key pair.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of communication technology, and in particular relates to a management method, device, equipment and storage medium for an SSH key. Background Art

[0002] Secure Shell, also known as SSH, is an encrypted network protocol that allows users to securely access and communicate with remote systems through an insecure network. SSH key pairs are a safe and convenient way to log in to SSH. They consist of a public key and a private key. The private key is stored on the client and the public key is stored on the server. The authorized_keys file is a special place for storing public keys in the Linux operating system. Each user has his own authorized_keys file. Each line in the file corresponds to a public key. The public key is generally divided into three parts: key type, base64-encoded key, and comment, separated by spaces.

[0003] Although key pairs are secure, they are difficult to maintain. The keys are in lines of obscure characters in authorized_keys, and the SSH key itself has no validity mechanism. Once added to the authorized_keys file, it is always valid, which increases the risk of key pair leakage. In addition, the key pair can only be invalidated by manually deleting the public key in the authorized_keys file. Especially for those who want to temporarily authorize users to log in to the server, the management of key pairs is even more difficult.

[0004] Currently, key management can only be performed manually by operation and maintenance personnel, and major cloud vendors can only list the key pairs configured in the server on the web page, which can be deleted manually by users.

[0005] Manual deletion of key pairs by operation and maintenance personnel has the following problems:

[0006] 1) Time-consuming and laborious. Manual operation requires maintenance personnel to log in to the server or cloud platform management page to perform the deletion action. When the number of servers and users to be maintained is large, the maintenance of key pairs will consume a lot of manpower.

[0007] 2) It is impossible to accurately control the validity period of key pairs. Operation and maintenance personnel cannot accurately control the deletion time of each public key in the long term, and it is even more difficult to achieve minute-level validity period control.

[0008] 3) There is a risk of accidental deletion. The public key in the authorized_keys file is a long string of characters with no regularity. Manual operation can easily lead to accidental deletion, which will affect normal user login authentication. Summary of the invention

[0009] The present invention aims to solve the problem that the validity period of a key pair cannot be accurately set in the related art at least to a certain extent. To this end, one object of the present invention is to provide a management method, apparatus, device and storage medium for SSH keys.

[0010] In order to solve the above technical problems, the embodiments of the present invention provide the following technical solutions:

[0011] A method for managing an SSH key, comprising:

[0012] The server to be accessed obtains the public key;

[0013] The server to be accessed stores the public key in the authorized_keys file of the server to be accessed;

[0014] The server to be accessed stores the information of the public key; wherein the information of the public key includes validity period information;

[0015] The server to be accessed obtains information of the expired public key according to the validity period information;

[0016] The server to be accessed deletes the expired public key.

[0017] The embodiments of the present invention can set the validity period of the public key while configuring the public key according to actual needs, and can automatically delete expired public keys; on the one hand, it reduces the manpower requirements for manually configuring key pairs and reduces failures caused by human errors; on the other hand, it can accurately set the validity period of the key pair, improve the flexibility of the key pair configuration, and increase the use scenarios of the key pair.

[0018] Optionally, after the server to be accessed obtains the public key, the process further includes:

[0019] A key pair is created, wherein the key pair includes a public key and a private key. The server to be accessed can create not only a private key but also a public key, and has a wide range of applications.

[0020] Optionally, the server to be accessed stores the public key in an authorized_keys file of the server to be accessed, including:

[0021] The public key is stored in the authorized_keys file in a storage format; wherein the data information in the storage format includes the key type, the public key encoding, the key comment and the hash value in sequence, wherein the hash value is the hash value of the public key encoding.

[0022] In this embodiment of the present invention, in order to reduce the size of externally stored data, the MD5 value calculated by the key is used as the identifier of the corresponding public key, and the identifier is used to complete the deletion operation of the public key.

[0023] Optionally, the server to be accessed stores information of the public key, including:

[0024] The public key information is stored in an external medium, wherein the external medium includes at least one of a file, a database, and a message queue; the public key information also includes the IP address and user name of the server to be accessed.

[0025] In the embodiment of the present invention, the server IP is used to identify the server where the public key is located; the user name, the Linux system is multi-user, is used to identify the user to which the public key belongs, and can realize confirmation of the terminal and the server.

[0026] Optionally, the server to be accessed obtains information of the expired public key according to the validity period information, including:

[0027] Searching the storage information of the external medium to obtain the search result;

[0028] When the search result includes the information of the expired public key, the expired public key is confirmed according to the MD5 value corresponding to the expired public key to obtain a confirmation result; the expired public key is deleted according to the confirmation result; when the search result does not include the information of the expired public key, the search process is terminated;

[0029] Wherein, the external medium is a memory card or a mobile hard disk.

[0030] In the embodiments of the present invention, because the validity period information is set for the public key, the currently expired public key can be determined in advance or determined based on the retrieval result of the validity period information of the public key, thereby avoiding the problem of operation and maintenance personnel monitoring the validity period of each public key for a long time, saving time and effort, avoiding accidental deletion, and achieving accurate results.

[0031] Optionally, the server to be accessed obtains information of the expired public key according to the validity period information, further comprising:

[0032] Receive the information of the expired public key pushed by the message queue.

[0033] In an embodiment of the present invention, when the message queue sends the information of the expired public key to the processor, the processor verifies the MD5 hash value of the received expired public key. If the verification is consistent, the operation of deleting the expired public key is triggered. The expired public key is deleted, and the user can no longer access the server, thereby realizing timely deletion of unnecessary keys and saving system storage space.

[0034] Optionally, deleting the expired public key includes:

[0035] When the retrieval result includes the information of the expired public key, the expired public key is confirmed according to the MD5 value corresponding to the expired public key to obtain a confirmation result; the expired public key is deleted according to the confirmation result; when the retrieval result does not include the information of the expired public key, the retrieval process is terminated.

[0036] The embodiments of the present invention avoid manual deletion of public keys by operation and maintenance personnel through automatic deletion of public keys, and the operation is accurate, accidental deletion is avoided, operation efficiency is saved, user experience is improved, and the security of the user access to the server is guaranteed.

[0037] An embodiment of the present invention further provides a SSH key management device, comprising:

[0038] An acquisition module is used to obtain a public key from a server to be accessed;

[0039] A storage module stores the public key in the authorized_keys file of the server to be accessed;

[0040] An access module, used for the server to be accessed to store the information of the public key; wherein the information of the public key includes validity period information;

[0041] A confirmation module, used for the server to be accessed to obtain information of the expired public key according to the validity period information;

[0042] A management module is used for the server to be accessed to delete the expired public key.

[0043] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the computer program.

[0044] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the above method when executed by a processor.

[0045] The embodiments of the present invention have the following technical effects:

[0046] The above-mentioned technical scheme of the present invention can set the validity period of the public key when configuring the public key according to actual needs, and can automatically delete the expired public key; on the one hand, it reduces the manpower requirements for manually configuring the key pair and reduces the failures caused by human errors; on the other hand, it can accurately set the validity period of the key pair, improve the flexibility of the key pair configuration, and increase the usage scenarios of the key pair.

[0047] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 It is a flowchart of a method for managing an SSH key provided by an embodiment of the present invention;

[0049] Figure 2 It is a schematic diagram of the format of storing the public key provided by an embodiment of the present invention;

[0050] Figure 3 It is a schematic diagram of a flow chart of deleting an expired public key according to a search result provided by an embodiment of the present invention;

[0051] Figure 4 It is a schematic diagram of a process of deleting an expired public key according to a push result provided by an embodiment of the present invention;

[0052] Figure 5 This is a schematic diagram of an application scenario process provided by an embodiment of the present invention;

[0053] Figure 6 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0054] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.

[0055] The SSH (Secure Shell) mentioned in the present invention is a secure shell protocol; the authorized_keys file is used to store the public key for remote password-free login; linux (GNU / Linux) is an operating system; base64 encoding is a character set including 64 characters, and any symbol can be converted into a character in this character set. This conversion process is called base64 encoding; MD5 is a message digest algorithm.

[0056] like Figure 1 As shown, an embodiment of the present invention provides a method for managing an SSH key, including:

[0057] Step S1: The server to be accessed obtains a public key;

[0058] Specifically, the public key is determined according to the private key and the information of the server to be accessed.

[0059] Step S2: storing the public key in the authorized_keys file of the server to be accessed;

[0060] Specifically, it is used to parse according to the format to determine whether the public key is the public key to be deleted.

[0061] Step S3: storing the public key information; wherein the public key information includes validity period information;

[0062] Specifically, after receiving the public key, the server stores the information carried by the public key in a memory to provide instructions for subsequent retrieval, search, and push of expired public keys.

[0063] Step S4: Obtaining information of the expired public key according to the validity period information;

[0064] Specifically, when the key pair is generated, the validity period of the newly generated public key can be set.

[0065] Step S5: Delete the expired public key.

[0066] Specifically, by automatically deleting the public key, the operation and maintenance personnel can avoid manual deletion of the public key, and the operation is accurate, which can avoid accidental deletion, save operational efficiency, improve user experience, and ensure the security of users' access to the server.

[0067] This embodiment of the present invention can set the validity period of a key pair when configuring a new key according to actual needs, and can automatically delete expired public keys; on the one hand, it reduces the manpower requirements for manually configuring key pairs and reduces failures caused by human errors; on the other hand, it can accurately set the validity period of the key pair, improve the flexibility of key pair configuration, and increase the usage scenarios of the key pair.

[0068] In an optional embodiment of the present invention, in step S1, after the server to be accessed obtains the public key, the method further includes:

[0069] Step S11: Create a key pair, the key pair including a public key and a private key.

[0070] The server to be accessed

[0071] like Figure 2 As shown, in an optional embodiment of the present invention, in step S2, the public key is stored in the authorized_keys file of the server to be accessed, including:

[0072] Step S21: Store the public key in the authorized_keys file in a storage format; wherein the data information in the storage format includes the key type, public key encoding, key comment and hash value in sequence, wherein the hash value is the hash value of the public key encoding.

[0073] Specifically, the public key is encoded in base64, and the hash value is the base64 encoding of the public key generated by the MD5 algorithm. The base64 encoding of the public key or its MD5 hash value is used to identify the public key corresponding to the expired information.

[0074] In this embodiment of the present invention, in order to reduce the size of externally stored data, the MD5 value calculated by the key is used as the identifier of the corresponding public key, and the identifier is used to complete the deletion operation of the public key.

[0075] In an optional embodiment of the present invention, in step S3, storing the information of the public key includes:

[0076] Step S31: storing the public key information to an external medium, wherein the external medium includes at least one of a file, a database, and a message queue; the public key information also includes the IP address and user name of the server to be accessed.

[0077] Specifically, the server IP is used to identify the server where the public key is located; the user name, the Linux system is multi-user, is used to identify the user to which the public key belongs.

[0078] This embodiment of the present invention is used to confirm a terminal and a server to be accessed.

[0079] like Figure 3 As shown, in an optional embodiment of the present invention, in step S4, the server to be accessed obtains information of the expired public key according to the validity period information, including:

[0080] Step S41: searching the storage information of the external medium to obtain the search result;

[0081] Step S42: When the retrieval result includes the information of the expired public key, the expired public key is confirmed according to the MD5 value corresponding to the expired public key to obtain a confirmation result; the expired public key is deleted according to the confirmation result; when the retrieval result does not include the information of the expired public key, the retrieval process is terminated.

[0082] In actual application scenarios, within the validity period of the public key, the processor searches the external medium (memory card or mobile hard disk) that stores the validity period information of the public key. When information about expired public key is retrieved, the MD5 hash value of the expired public key is verified. If they are consistent, the public key deletion action is triggered, the public key is deleted, and the user can no longer access the server.

[0083] If the search result is that there is no information about the expired public key, then the search is terminated and the above steps are repeated until the expired public key is found and the expired public key is deleted.

[0084] In the embodiments of the present invention, because the validity period information is set for the public key, the currently expired public key can be determined in advance or determined based on the retrieval result of the validity period information of the public key, thereby avoiding the problem of operation and maintenance personnel monitoring the validity period of each public key for a long time, saving time and effort, avoiding accidental deletion, and achieving accurate results.

[0085] like Figure 4 As shown, in an optional embodiment of the present invention, in step S4, the server to be accessed obtains information of the expired public key according to the validity period information, further comprising:

[0086] Step S41a: Receive the information of the expired public key pushed by the message queue.

[0087] When the message queue sends the expired public key information to the processor, the processor verifies the MD5 hash value of the received expired public key. If the verification is consistent, the operation of deleting the expired public key is triggered. The expired public key is deleted and the user can no longer access the server.

[0088] The embodiments of the present invention realize timely deletion of unnecessary public keys, thus saving storage space of the system.

[0089] like Figure 5 As shown, the above embodiments of the present invention can be implemented by the following implementation methods:

[0090] 1) Create a key pair, where the public key is stored in the server to be accessed.

[0091] 2) Add the public key to the authorized_keys file corresponding to the user, and save the private key in the user terminal; store the validity information of the public key to an external medium, such as a file; the external medium may be a memory card or a mobile hard disk.

[0092] 3) The user can log in to the server to be accessed without a password. When the public key expires and is deleted, the user can no longer access the server to be accessed.

[0093] like Figure 6As shown, an embodiment of the present invention further provides a SSH key management device, including:

[0094] An acquisition module is used to obtain a public key from a server to be accessed;

[0095] A storage module stores the public key in the authorized_keys file of the server to be accessed;

[0096] An access module, used for the server to be accessed to store the information of the public key; wherein the information of the public key includes validity period information;

[0097] A confirmation module, used for the server to be accessed to obtain information of the expired public key according to the validity period information;

[0098] A management module is used for the server to be accessed to delete the expired public key.

[0099] Specifically, the management device runs on the server to be accessed.

[0100] The embodiment of the present invention further provides a computer device 60, including a memory 62, a processor 61, and a computer program stored in the memory 62 and executable on the processor 61, wherein the processor 61 implements the above-mentioned method when executing the computer program.

[0101] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the above method when executed by a processor.

[0102] In addition, other structures and functions of the SSH key pair in the embodiment of the present invention are known to those skilled in the art and are not described herein in detail to reduce redundancy.

[0103] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.

[0104] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0105] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0106] In the description of the present invention, it is to be understood that the terms “center”, “longitudinal”, “lateral”, “length”, “width”, “thickness”, “up”, “down”, “front”, “back”, “left”, “right”, “vertical”, “horizontal”, “top”, “bottom”, “inside”, “outside”, “clockwise”, “counterclockwise”, “axial”, “radial”, “circumferential”, etc., indicating orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as limiting the present invention.

[0107] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0108] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0109] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may mean that the first and second features are in direct contact, or the first and second features are in indirect contact through an intermediate medium. Moreover, a first feature being "above", "above" or "above" a second feature may mean that the first feature is directly above or obliquely above the second feature, or simply means that the first feature is higher in level than the second feature. A first feature being "below", "below" or "below" a second feature may mean that the first feature is directly below or obliquely below the second feature, or simply means that the first feature is lower in level than the second feature.

[0110] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A method for managing SSH keys, characterized in that: include: The server to be accessed obtains the public key; The public key is stored in the authorized_keys file of the server to be accessed; The server to be accessed stores the information of the public key; wherein the information of the public key includes validity period information; The server to be accessed obtains information of the expired public key according to the validity period information; The server to be accessed deletes the expired public key; The server to be accessed stores information of the public key, including: The public key information is stored in an external medium, wherein the external medium includes at least one of a file, a database, and a message queue; the public key information also includes the IP address and user name of the server to be accessed; The server to be accessed obtains information of the expired public key according to the validity period information, including: Searching the storage information of the external medium to obtain the search result; When the retrieval result includes the information of the expired public key, the expired public key is confirmed according to the MD5 value corresponding to the expired public key to obtain a confirmation result; the expired public key is deleted according to the confirmation result; when the retrieval result does not include the information of the expired public key, the retrieval process is terminated.

2. The method according to claim 1, characterized in that: After the server to be accessed obtains the public key, the following steps are also included: A key pair is created, the key pair comprising a public key and a private key.

3. The method according to claim 1, characterized in that The server to be accessed stores the public key in the authorized_keys file of the server to be accessed, including: The public key is stored in the authorized_keys file in a storage format; wherein the data information in the storage format includes the key type, the public key encoding, the key comment and the hash value in sequence, wherein the hash value is the hash value of the public key encoding.

4. The method according to claim 1, characterized in that The server to be accessed obtains the information of the expired public key according to the validity period information, and also includes: receiving the information of the expired public key pushed by the message queue.

5. A SSH key management device, characterized in that: include: An acquisition module is used to obtain a public key from a server to be accessed; A storage module stores the public key in the authorized_keys file of the server to be accessed; An access module, used for the server to be accessed to store the information of the public key; wherein the information of the public key includes validity period information; A confirmation module, used for the server to be accessed to obtain information of the expired public key according to the validity period information; A management module, used for the server to be accessed to delete the expired public key; The server to be accessed stores information of the public key, including: The public key information is stored in an external medium, wherein the external medium includes at least one of a file, a database, and a message queue; the public key information also includes the IP address and user name of the server to be accessed; The server to be accessed obtains information of the expired public key according to the validity period information, including: Searching the storage information of the external medium to obtain the search result; When the retrieval result includes the information of the expired public key, the expired public key is confirmed according to the MD5 value corresponding to the expired public key to obtain a confirmation result; the expired public key is deleted according to the confirmation result; when the retrieval result does not include the information of the expired public key, the retrieval process is terminated.

6. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.