简体   繁体   English

如何获取 AWS EC2 密钥对创建日期?

[英]How to obtain AWS EC2 key-pair creation date?

To access ec2 instances, we need to create a ssh key-pair .要访问 ec2 实例,我们需要创建一个 ssh 密钥对。 I need to extract the date on which the key-pair was created ?我需要提取创建密钥对的日期吗? Is it possible using aws sdk apis ?是否可以使用 aws sdk apis?

The AWS SDK does not provide a way to get the dates from a key pair generated. AWS开发工具包未提供从生成的密钥对中获取日期的方法。 There is no API to retrieve the Private Key. 没有API可以检索私钥。 The Public key can be retrieved via some languages SDK's. 可以通过某些语言的SDK检索公共密钥。 However it is only accessable if running inside of an ec2 instance because they run a command such as curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key to obtain the key and the metadata is only available from within EC2. 但是,只有在ec2实例内部运行时才可以访问它,因为它们运行诸如curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key类的命令来获取密钥和元数据仅在EC2中可用。

That being said I've never heard of being able to get a date from an ssh key pair. 话虽如此,我从未听说过能够从ssh密钥对获取日期。 If you can show me how this is accomplished I can maybe whip something up that works for you. 如果您可以告诉我这是如何完成的,我也许可以为您解决一些问题。 The EC2 ssh key pair is no different than any other key pair. EC2 ssh密钥对与任何其他密钥对没有不同。 The answer to your question remains the same, the SDK does not provide this function. 您问题的答案保持不变,SDK不提供此功能。

1 way to get an idea of when the key pair was initially generated, is to look at the Launch Time of the EC2 Instance(s) using it.了解密钥对最初生成时间的一种方法是查看使用它的 EC2 实例的启动时间。 This will not give you the actual creation date, especially if your EC2 Instances are very ephemeral but it may help narrow it down.这不会为您提供实际的创建日期,特别是如果您的 EC2 实例非常短暂,但它可能有助于缩小范围。 Another way to get an idea of when the key pair was initially generated is to look at when the AMI was created that is used to spin up your EC2 Instances using that key pair.了解最初生成密钥对的时间的另一种方法是查看创建 AMI 的时间,该 AMI 用于使用该密钥对启动您的 EC2 实例。 Assuming you've used your own AMI to create Instances from.假设您已使用自己的 AMI 从中创建实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM