跳至内容

为什么我无法使用会话管理器连接到我的 Amazon EC2 实例?

3 分钟阅读
0

我无法使用会话管理器(AWS Systems Manager 的一项功能)访问我的 Amazon Elastic Compute Cloud (Amazon EC2) 实例。

解决方案

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

以下原因可能会导致您的会话管理器无法连接到您的 EC2 实例:

  • 缺少会话管理器先决条件
  • AWS Identity and Access Management (IAM) 权限问题
  • 会话管理器的 Preferences(首选项)配置不正确
  • 会话管理器插件问题
  • 连接问题

要确定连接问题的根本原因并检查错误消息,请查看 AWS Systems Manager Agent (SSM Agent) 日志

检查您是否满足会话管理器先决条件

确保实例使用托管节点,且您的配置符合会话管理器先决条件。有关详细信息,请参阅为什么 Systems Manager 没有将我的 Amazon EC2 实例显示为托管实例?

如果您运行 SSM Agent 版本 3.1.501.0,则可以使用 ssm-cli 来检查实例是否满足会话管理器先决条件。ssm-cli 工具可用于确定 Systems Manager 为何没有将正在运行的实例包含在托管实例列表中。

验证您的 IAM 用户或角色是否具有必要的 IAM 策略

确认您用于连接到 EC2 实例的 IAM 用户或角色具有会话管理器所需的 IAM 策略和权限

对“会话管理器首选项”设置中的问题进行故障排除

检查您的 AWS KMS 配置

您可以在会话管理器中启用 AWS Key Management Service (AWS KMS) 加密。如果您启用了 AWS KMS,但实例无法访问 AWS KMS 端点,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: ----------ERROR------- Encountered error while initiating handshake.Handshake timed out.Please ensure that you have the latest version of the session manager plugin.”

要检查与 AWS KMS 端点的连接,请运行以下命令:

telnet kms.RegionID.amazonaws.com 443

**注意:**请将 RegionID 替换为您的 AWS 区域

如果输出显示您无法连接到 AWS KMS 端点,请设置与 AWS KMS 虚拟私有云 (VPC) 端点的连接

如果实例配置文件或 IAM 用户对密钥没有 kms:Decrypt 权限,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: ----------ERROR------- Encountered error while initiating handshake.Fetching data key failed: Unable to retrieve data key, Error when decrypting data key AccessDeniedException: User: arn:aws:sts::account id:assumed-role/instance-profile/instance-id is not authorized to perform: kms:Decrypt on resource: arn:aws:kms:region:account id:key/key-id because no identity-based policy allows the kms:Decrypt action status code: 400”

要解决此问题,请为用于加密会话的 AWS KMS 密钥添加 kms:Decrypt 权限

如果您在会话管理器中指定的 AWS KMS 密钥的 Amazon 资源名称 (ARN) 不正确或已不存在,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: Error calling KMS GenerateDataKey API: NotFoundException: Key 'arn:aws:kms:region:account:key/abcdxyz' does not exist”

要解决此问题,请检查 AWS KMS 密钥的 ARN,确保其正确无误。

检查您的 Amazon S3 配置

您可以将会话数据存储在 Amazon Simple Storage Service (Amazon S3) 存储桶中。如果您使用日志加密且实例配置文件没有 s3:GetEncryptionConfiguration 权限,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: Couldn't start the session because we are unable to validate encryption on Amazon S3 bucket.Error: AccessDenied: User:abcd is not authorized to perform: s3:GetEncryptionConfiguration on resource”

要解决此问题,请在实例配置文件中添加 s3:GetEncryptionConfiguration 权限

如果您在会话管理器中配置的 S3 存储桶不存在,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: Couldn't start the session because we are unable to validate encryption on Amazon S3 bucket.Error: NoSuchBucket: The specified bucket does not exist status code: 404”

要解决此问题,请验证您在会话管理器中指定的存储桶是否正确且可用。

检查您的操作系统配置

如果您在 Linux 实例上启用运行方式支持,则可以使用操作系统 (OS) 用户凭证启动会话。但是,如果操作系统用户名不存在,则您会收到以下错误消息:

“Your session has been terminated for the following reasons: ----------ERROR------- Unable to start command: failed to start pty since RunAs user username does not exist”

要解决此问题,请确保使用适用于您的操作系统的正确默认用户名,或确保自定义用户名准确无误。

**重要事项:**您不能使用操作系统根用户账户对与会话管理器的连接进行身份验证。

对会话管理器插件问题进行故障排除

如果实例的根 Amazon Elastic Block Store (Amazon EBS) 卷已满,SSM Agent 将无法创建所需的文件。您会收到以下错误消息:

“Your session has been terminated for the following reasons: Plugin with name Standard_Stream not found.Step name: Standard_Stream”

要解决此问题,请增加 Amazon EBS 卷的大小,然后扩展文件系统。或者,删除不使用的文件,以在实例上释放更多磁盘空间。

如果您使用 AWS CLI 连接实例,则必须在本地计算机上安装会话管理器插件。如果您不安装插件,则会收到以下错误消息:

“SessionManagerPlugin is not found.Please refer to SessionManager Documentation here: http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found”

对连接问题进行故障排除

启动会话管理器会话后,您可能会看到带有闪烁光标的空白屏幕。如果您遇到此问题,则表示您的本地计算机可能未连接到您的会话管理器端点。

要检查与 AWS 会话管理器端点的连接,请根据您的操作系统运行以下命令。

Linux:

telnet ssmmessages.RegionID.amazonaws.com 443

**注意:**请将 RegionID 替换为您的区域。

Windows:

Test-NetConnection ssmmessages.RegionID.amazonaws.com -port 443

**注意:**请将 RegionID 替换为您的区域。

如果您的实例位于私有子网中,请参阅如何创建 Amazon Virtual Private Cloud (Amazon VPC) 端点,才能在不连接互联网的情况下使用 Systems Manager 管理私有 Amazon EC2 实例?

有关其他故障排除场景,请参阅如何排查 AWS Systems Manager 会话管理器的问题?

相关信息

会话管理器故障排除

如何通过 Systems Manager 使用 SSH 隧道访问我的私有 VPC 资源?

通过会话管理器允许和控制 SSH 连接的权限

启用和禁用会话日志记录

AWS 官方已更新 10 个月前