0
0

[備忘録] macOS で AWS Session Manager(SSM) を使ってLinuxサーバーに接続できるようになるまで

Posted at

はじめに

macOSのターミナルから下記コマンドでLinuxサーバーに接続しようとしたところ、Session Manager プラグイン がないと怒られた。

% aws ssm start-session --target ${踏み台EC2のID}
SessionManagerPlugin is not found. Please refer to SessionManager Documentation here: http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found

そこで、Session Manager プラグインをインストールしたのだが、インストールできるまでいくつかのエラーに遭遇したのでここに記す。

実施したこと

[エラー1] SessionManagerPlugin is not found.

まずは、公式ドキュメントの手順に沿って、Session Manager プラグインのインストールを試みた。

インストーラのダウンロード

% curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/mac/sessionmanager-bundle.zip" -o "sessionmanager-bundle.zip"

パッケージの解凍

% unzip sessionmanager-bundle.zip

インストールコマンド実行

% sudo ./sessionmanager-bundle/install -i /usr/local/sessionmanagerplugin -b /usr/local/bin/session-manager-plugin

ここで、下記エラーが発生。

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

公式ドキュメントに「Python 2.6.5 以降、または Python 3.3 以降が必要」と注意書きがあったので、Pythonのバージョンを確認したところ、Pythonがインストールされていなかった。

% python -v
zsh: command not found: python

[エラー2] zsh: command not found: python

次にPythonのインストールを行う。
Homebrew はインストール済み、pyenv は未インストールの状態のため、pyenv -> Pythonの順にインストールする。

% brew -v
Homebrew 4.0.28
% pyenv -v
zsh: command not found: pyenv

下記コマンドで pyenv をインストール後、

% brew install pyenv

参考資料に従って pyenv の設定を行った。

% pyenv -v          
pyenv 2.3.24
% echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
% echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(pyenv init -)"' >> ~/.zshrc
% source ~/.zshrc

そしていよいよ Python のインストールをしたところ、またエラーが発生した。

% pyenv install 3.11.4
...
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

[エラー3] xcrun: error: invalid active developer path

macOSのアップデート後あるあるのエラーらしく、xcodeをインストールすれば解決するようなので、インストールした。

% xcode-select --install

解決編 🎉

再度Pythonのインストールと設定をすると、無事に Python 3.11.4 を使用できるようになった。

% pyenv install 3.11.4
% pyenv versions        
* system (set by /Users/user/.pyenv/version)
  3.11.4
% pyenv global 3.11.4
% python --version   
Python 3.11.4

そして、Session Manager プラグインのインストールも成功。

% sudo ./sessionmanager-bundle/install -i /usr/local/sessionmanagerplugin -b /usr/local/bin/session-manager-plugin  
...
Installation successful!

最初にやりたかったことである、Linuxサーバーへの接続も無事行えた。

% aws ssm start-session --target ${踏み台EC2のID}
Starting session with SessionId: *****

最後に

参考にした文献を記す。

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