為什麼我無法使用 Session Manager 連線至 Amazon EC2 執行個體?
我無法使用 AWS Systems Manager 的 Session Manager 功能,來存取 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
以下原因可能導致您的 Session Manager 無法連線到 EC2 執行個體:
- 缺少 Session Manager 先決條件
- AWS Identity and Access Management (IAM) 權限問題
- Session Manager 偏好設定組態不正確
- Session Manager 外掛程式問題
- 連線問題
若要確定連線問題的根本原因並檢查錯誤訊息,請檢查 AWS Systems Manager Agent (SSM Agent) 日誌。
檢查您是否符合 Session Manager 先決條件
請確定執行個體使用受管節點,且您的設定符合 Session Manager 先決條件。如需詳細資訊,請參閱為什麼 Systems Manager 沒有將我的 Amazon EC2 執行個體顯示為受管執行個體?
如果您執行的是 SSM 代理程式版本 3.1.501.0,則可以使用 ssm-cli 檢查執行個體是否符合 Session Manager 先決條件。ssm-cli 工具可確定 Systems Manager 未在受管執行個體清單中包含執行中執行個體的原因。
確認您的 IAM 使用者或角色是否具有必要的 IAM 政策
確認用於連接到 EC2 執行個體的 IAM 使用者或角色具有必要的 Session Manager IAM 政策和權限。
對 Session Manager 偏好設定中的問題進行疑難排解
檢查您的 AWS KMS 組態
您可以在 Session Manager 中啟用 AWS Key Management Service (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." (您的工作階段已終止,原因如下:----------錯誤------- 啟動交握時遇到錯誤。交握逾時。請確定您擁有最新版本的 Session Manager 外掛程式。)
若要檢查與 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" (您的工作階段已終止,原因如下:----------錯誤------- 啟動交握時遇到錯誤。取得資料金鑰失敗:無法擷取資料金鑰,解密資料金鑰 AccessDeniedException 時發生錯誤:使用者:arn:aws:sts::account id:assumed-role/instance-profile/instance-id 無權對資源:arn:aws:kms:region:account id:key/key-id 執行 kms:Decrypt 作業,因為沒有身分型政策允許 kms:Decrypt 動作,狀態碼:400)
若要解決此問題,請為用於加密工作階段的 AWS KMS key 新增 kms:Decrypt 權限。
如果您在 Session Manager 中指定的 AWS KMS key 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" (您的工作階段因以下原因終止:呼叫 KMS GenerateDataKey API 時發生錯誤:NotFoundException:金鑰 'arn:aws:kms:region:account:key/abcdxyz' 不存在)
若要解決此問題,請檢查 AWS KMS key 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" (無法啟動工作階段,因為我們無法驗證 Amazon S3 儲存貯體上的加密。錯誤:AccessDenied:使用者:abcd 無權對資源執行:s3:GetEncryptionConfiguration)
若要解決此問題,請為執行個體設定檔新增 s3:GetEncryptionConfiguration 權限。
如果您在 Session Manager 中設定的 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" (您的工作階段因以下原因終止:無法啟動工作階段,因為我們無法驗證 Amazon S3 儲存貯體上的加密。錯誤:NoSuchBucket:指定的儲存貯體不存在狀態碼:404)
若要解決此問題,請確認您在 Session Manager 中指定的儲存貯體是否正確且可用。
檢查您的作業系統組態
如果您在 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 " (您的工作階段已終止,原因如下:----------錯誤-------無法啟動命令:無法啟動 pty,因為 RunAs 使用者 username 不存在)
若要解決此問題,請確定您使用了正確的作業系統預設使用者名稱,或自訂使用者名稱是準確的。
**重要:**您不能使用作業系統根使用者帳戶來驗證與 Session Manager 的連線。
對 Session Manager 外掛程式問題進行疑難排解
如果執行個體的根 Amazon Elastic Block Store (Amazon EBS) 磁碟區已滿,則 SSM 代理程式無法建立所需的檔案。您會收到以下錯誤訊息:
"Your session has been terminated for the following reasons: Plugin with name Standard_Stream not found.Step name: Standard_Stream" (您的工作階段已終止,原因如下:找不到名為 Standard_Stream 的外掛程式。步驟名稱:Standard_Stream)
若要解決此問題,請增加 Amazon EBS 磁碟區大小,然後擴充檔案系統。或者,刪除不使用的檔案以釋放執行個體上更多的磁碟空間。
如果您使用 AWS CLI 連線到執行個體,則必須在本機上安裝 Session Manager 外掛程式。如果您未安裝該外掛程式,那麼您將收到以下錯誤訊息:
"SessionManagerPlugin is not found.Please refer to SessionManager Documentation here: http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found" (找不到 SessionManagerPlugin。請參閱此處的 SessionManager 文件:http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found)
對連線問題進行疑難排解
啟動 Session Manager 工作階段後,您可能會看到一個空白畫面,畫面上只有一個閃爍的游標。如果您遇到此問題,則您的本機電腦可能未連線到 Session Manager 端點。
若要檢查與 AWS Session Manager 端點的連線,請根據您的作業系統執行下列命令。
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 Session Manager 的問題進行疑難排解?
相關資訊
如何透過 Systems Manager 使用 SSH 通道來存取我的私有 VPC 資源?
相關內容
- 已提問 2 年前
- 已提問 1 年前