LoginSignup
0
0

AWS CLI経由でSSM接続できなくなって何とかなった

Last updated at Posted at 2023-11-08

概要

CLIのアクセスキー誤りでCLI経由のSSM接続が出来なくなって、なんとかなった

環境

  • クライアント側:Windows 10
  • サーバ側:Amazon Linux

やったこと

こんな感じのconfigファイルで

Host instance-id
    User username
    IdentityFile /path/to/prvate_key
    ProxyCommand "C:\Program Files\Amazon\AWSCLIV2\aws.exe" ssm start-session --target instance-id --document-name AWS-StartSSHSession --parameters portNumber=%p

こんな感じで接続しようとした

$ ssh instance-id

403エラーが出た

An error occurred (403) when calling the StartSession operation: Server authentication failed: <UnauthorizedRequest><message>Forbidden.</message></UnauthorizedRequest>

インスタンス側のログに接続を試みた形跡が無かったので、ここでクライアント側の何らかの設定不備を疑う。STSの認証情報を確認したらこんなエラーが出た

$ aws sts get-caller-identity

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity 
operation: The security token included in the request is invalid.

そういえば別のアカウントのアクセスキーをCLIに登録してた気がする…ので/.aws配下をすべて削除後、再度aws configureでアクセスキーを登録し直し。(参考①)

$ aws configure
AWS Access Key ID [None]: **********************
AWS Secret Access Key [None]: *************************
Default region name [None]: your_region_name
Default output format [None]: json

認証情報を見てみる。

$ aws sts get-caller-identity
{
    "UserId": "*************************",
    "Account": "************",
    "Arn": "arn:aws:iam::************:user/username"
}

通った!ので再度ssh接続してみる。

$ ssh instance-id

Last login: Wed Nov  8 12:29:43 2023 from *******

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI    
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/ 

トラブルシュート成功!

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0