# シークレットマネージャーCLI

![](/files/Nv1wsIorDLhdpen4M2ko)

## 概要

**KeeperシークレットマネージャーCLI (KSM CLI)** を使用すると、ターミナル、シェルスクリプト、シェルから起動できる任意のソフトウェアから、シークレットマネージャーボルトの基本的な操作をご利用になれます。

### 基本機能

* Keeperボルトからシークレットを取得
* Keeperボルトのシークレットを更新
* サードパーティのCI/CDやその他の開発ツールとの統合
* Keeperと外部のシークレットプロバイダ間でシークレットを同期
* スクリプトおよびコンテナ内の環境変数をKeeperシークレットへの置換

{% hint style="info" %}
Keeperでは2つの異なるCLIツールがご利用になれます。シークレットマネージャーCLIはマシンベースのシークレット管理を対象とする一方、[コマンダーCLI](/jp/keeperpam/commander-cli/overview.md)では管理機能に重点を置いています。
{% endhint %}

![](/files/NVdVcbeRd4oVuFHRCrQf)

### セキュアな構成の保管 <a href="#secure-credential-storage" id="secure-credential-storage"></a>

KSM CLIは、既定でオペレーティングシステム標準のセキュアストレージに構成を安全に保存します。認証情報を設定ファイルに保存する方法と比べると、セキュリティが強化されます。

#### 動作の概要 <a href="#how-it-works" id="how-it-works"></a>

| OS      | セキュアストレージのバックエンド                        |
| ------- | --------------------------------------- |
| macOS   | キーチェーン                                  |
| Windows | Windows 資格情報マネージャー                      |
| Linux   | Secret Service（GNOME Keyring、KWalletなど） |

プロファイルを初期化すると、認証情報はOS標準のセキュアストレージに自動的に保存されます。ファイルベースの保管を明示的に指定しない限り、`keeper.ini` ファイルは作成されません。

#### OS標準ストレージの利点 <a href="#benefits-of-os-native-storage" id="benefits-of-os-native-storage"></a>

* **セキュリティの強化**: OSレベルの暗号化で認証情報を保護します
* **平文ファイルの排除**: 認証情報ファイルの誤露出リスクを減らします
* **自動的な保護**: 生体認証やシステムパスワードなど、既存のOSのセキュリティ機能を利用します
* **複数プロファイル**: 複数のKSMプロファイルを安全に管理しやすくなります

**注:** OS標準のセキュアストレージには、オプションの `keyring` エクストラのインストールが必要です（例: `pip3 install keeper-secrets-manager-cli[keyring]`）。これがない場合、プロファイルは `keeper.ini` を使ったファイルベースの保管にフォールバックします。

***

## アプリケーションとクライアントデバイスの設定

シークレットマネージャーCLIを使用する場合、またはKeeperボルトに保存されたシークレットへのアクセスに環境変数の置換を使う場合は、先にアプリケーションとクライアントデバイスを設定してください。[クイックスタートガイド](/jp/keeperpam/secrets-manager/quick-start-guide.md)をご参照のうえ設定してください。

## シークレットマネージャーCLIのインストール

KSM CLIは、Windows/Mac/Linux用のバイナリアプリケーションとして、またはPython環境用のpip3インストールとしてご利用になれます。

#### バイナリのインストール方法

最新のバイナリリリースは、[GitHubリポジトリ](https://github.com/Keeper-Security/secrets-manager/releases?q=cli\&expanded=true)で入手できます。ご利用のオペレーティングシステムに合わせてインストーラーをダウンロードしてください。

:arrow\_down:[**Secrets Manager CLIバイナリのダウンロード**](https://github.com/Keeper-Security/secrets-manager/releases?q=cli\&expanded=true)

WindowsまたはMacOSでCLIを起動すると、CLIはシェルモードで実行されます。`ksm` コマンドは、コマンドラインから引き続きご利用になれます。

Linuxバイナリは単なる実行可能ファイルなので、**PATH**のディレクトリに移動する必要があります。

### Dockerのインストール方法

KeeperのDockerイメージからのインストールとセットアップについては、[Dockerコンテナ](/jp/keeperpam/secrets-manager/secrets-manager-command-line-interface/docker-container.md)のページをご参照ください。

### Pip3とPython3のインストール方法

Python 3.10以上がインストールされていることをご確認ください。インストールされていない場合は、OS固有のパッケージマネージャを使用してインストールします。

```
sudo yum install python3
```

pip3が最新であることを確認します。

```
sudo pip3 install --upgrade pip
```

これで、シークレットマネージャーCLIをインストールできます。

```
sudo pip3 install keeper-secrets-manager-cli
```

以下は最新バージョンにアップグレードするコマンドとなります。

```
sudo pip3 install -U keeper-secrets-manager-cli keeper-secrets-manager-core
```

この方法でCLIをシステムのPythonにインストールします。rootまたは管理者権限がない場合は、**virtualenv**を設定してCLIをインストールできます。**virtualenv**を使用しない場合は、LinuxまたはMac OSでは、モジュールとバイナリ&#x306F;**$HOME/.local**ディレクトリにインストールされます。**bin**ディレクトリへの**PATH**を含める必要がある場合があります。

詳しくはこちらの[Pythonパッケージウェブサイト](https://pypi.org/project/keeper-secrets-manager-cli/)をご参照ください。

#### virtualenvを使用したKSMのインストール

virtualenvを使用することで、クリーンに分離された環境にKSMをインストールできます。

```
sudo pip3 install virtualenv
```

```
virtualenv -p python3 my_env
```

```
source my_env/bin/activate
```

続いて、仮想環境にksmをインストールします

```
pip3 install keeper-secrets-manager-cli
```

#### **オプションのエクストラのインストール**

オプションのエクストラを併せてインストールすると、追加機能が使えるようになります。

**OS標準のセキュアストレージ（推奨）:**

`pip3 install keeper-secrets-manager-cli[keyring]`

> **注:** `keyring` エクストラを入れると、プロファイルをmacOSキーチェーン、Windows資格情報マネージャー、またはLinuxのSecret Serviceに保存できます。入れない場合、プロファイルはパーミッション `0600` のファイルベース保管にフォールバックします。

**AWS Secrets Managerへの同期:**

`pip3 install keeper-secrets-manager-cli[aws]`

> **注:** `aws` エクストラ（boto3）は、AWS Secrets Managerへ同期する `ksm sync` に必要です。既定ではインストールされません。

**すべてのエクストラをインストール:**

`pip3 install keeper-secrets-manager-cli[keyring,aws]`

### ソースコード

[GitHubリポジトリ](https://github.com/Keeper-Security/secrets-manager/tree/master/integration/keeper_secrets_manager_cli)でKeeperシークレットマネージャーCLIのソースコードを検索します。

### 使用方法

`ksm` のCLIツールは、以下の目的に使用できます。

* GitHub Actionsなどの統合で使う設定ファイルの初期化（`init`）
* クライアントデバイスとしてコマンドを実行するローカルプロファイルの作成（`profile`）
* Keeperボルトの照会とシークレットの取得（`secret`）
* 環境変数の置換のためのコマンドラインアプリケーションのラップ（`exec`）

```bash
ksm
```

```markup
Usage: ksm [OPTIONS] COMMAND [ARGS]...

  Keeper Secrets Manager CLI  Version: X.X.X

Options:
  --ini-file TEXT                INI config file.
  -p, --profile-name TEXT        Config profile
  -o, --output TEXT              Output [stdout|stderr|filename]
  -c, --color / -nc, --no-color  Use color in table views, where applicable.
  --cache / --no-cache           Enable/disable record caching.
  --log-level [DEBUG|INFO|WARNING|ERROR]
                                 Debug log level.
  --help                         Show this message and exit.

Commands:
  config       Configure the command line tool
  exec         Wrap an application and replace env variables
  init         Initialize a configuration file for integrations
  profile      Manage local client device profiles
  quit         Quit shell mode
  secret       Commands for secrets
  folder       Manage folders
  interpolate  Replace KSM notation placeholders in text files
  sync         Sync selected keys from Keeper vault to secure cloud based key value store
  shell        Run KSM in a shell
  version      Get module versions and information.

```

### ローカルクライアントデバイスの作成 <a href="#create-a-local-client-device" id="create-a-local-client-device"></a>

CLIは、`ksm profile init` にワンタイムアクセストークンを渡してクライアントデバイスとして初期化します。初期化後、CLIでシークレットを取得できます。以下の例では `XX:XXXX` をクライアントデバイスのワンタイムアクセストークンに置き換えます。

#### 既定の動作: OS標準のセキュアストレージ <a href="#default-behavior-os-native-secure-storage" id="default-behavior-os-native-secure-storage"></a>

既定では、KSM CLIをkeyring対応でインストールした場合（`pip3 install keeper-secrets-manager-cli[keyring]`）、構成はOS標準のセキュアストレージに保存されます。

```
ksm profile init XX:XXXX
```

**出力例（macOS）:**

```
Added profile _default to macOS Keychain
```

**出力例（Windows）:**

```
Added profile _default to Windows Credential Manager
```

**出力例（Linux）:**

```
Added profile _default to system keyring
```

初期化後、すぐにCLIを使用できます。

```
ksm secret list
```

#### 代替: ファイルベースの保管 <a href="#alternative-file-based-storage" id="alternative-file-based-storage"></a>

構成を設定ファイルに保存する場合は、`--ini-file` オプションを使用します。

```
ksm profile init --ini-file keeper.ini --token XX:XXXX
```

これにより、所有者のみが読み書きできるパーミッション（`0600`）の `keeper.ini` が作成されます。

### コンテナ／サーバーレス向け

**コンテナ、サーバーレス、ヘッドレス環境**（Docker、Kubernetes、CI/CD、クラウド関数など）では、keyringなしでKSM CLIをインストールします。

```
pip3 install keeper-secrets-manager-cli
```

トークンでプロファイルを初期化します。

```
ksm profile init --token XX:XXXX
```

OS標準のセキュアストレージが使えない環境向けに、`keeper.ini` 構成ファイルが作成されます。

***

コンテナの自動起動にCLIを含めている場合や `profile init` を実行したくない場合は、**`KSM_TOKEN`** を設定するとプロファイルが自動作成されます。

例:

```
KSM_TOKEN="XX:XXXX" ksm secret list
```

環境変数を設定すると、コマンドラインのフラグを減らせます。

| 環境変数                              | 説明                                                               |
| --------------------------------- | ---------------------------------------------------------------- |
| `KSM_CONFIG`                      | Base64エンコードされたKSM構成。設定されているとCLIはこの変数から構成を読み込みます。プロファイルの初期化は不要です。 |
| `KSM_TOKEN`                       | ワンタイムアクセストークン。設定され、INI構成が見つからない場合、既定プロファイルが自動作成されます（コンテナ向け）。     |
| `KSM_CLI_TOKEN`                   | `ksm profile init` 用のワンタイムアクセストークン。コマンドラインにトークンを載せない場合に使用します。    |
| `KSM_INI_FILE`                    | 既定の INI ファイル名（`keeper.ini`）を上書きします。                              |
| `KSM_INI_DIR`                     | `keeper.ini` の検索・作成先ディレクトリを上書きします。                               |
| `KSM_CLI_PROFILE`                 | 有効なプロファイル名を設定します（既定: `_default`）。                                |
| `KSM_HOSTNAME`                    | プロファイル初期化時のサーバー地域（既定: `US`）。`ksm profile init` の前に設定します。         |
| `KSM_CONFIG_KEYRING_UTILITY_PATH` | Linuxヘッドレス環境などで、代替keyringユーティリティ（例: `lkru`）へのパス。                 |

***

## コマンドの実行

Keeperシークレットマネージャーのコマンドは、コマンドラインから **`ksm`** プログラムで実行します。

**`ksm <コマンド> <サブコマンド> <オプション>`**

特定のコマンドのヘルプは、以下を実行します。

`ksm <コマンド> --help`

サブコマンドのヘルプは、以下を実行します。

`ksm <コマンド> <サブコマンド> --help`

| コマンド          | 説明                                   |
| ------------- | ------------------------------------ |
| `profile`     | ローカルクライアントデバイスのプロファイルを管理します          |
| `secret`      | シークレットを管理します（一覧、取得、更新、削除など）          |
| `folder`      | フォルダを管理します                           |
| `exec`        | アプリケーションをラップし、シークレットを環境変数として注入します    |
| `interpolate` | テキストファイル内のKSM表記法プレースホルダを置換します        |
| `sync`        | AWS、Azure、GCP、または JSON へシークレットを同期します |
| `config`      | CLIツールの設定を構成します                      |
| `init`        | 統合向けの構成ファイルを初期化します（k8s など）           |
| `version`     | バージョン情報を表示します                        |
| `shell`       | 対話型シェルモードで実行します                      |
| `quit`        | シェルモードを終了します                         |

**オプション**

`--ini-file </path/to/keeper.ini>`

`keeper.ini` 設定ファイルを指定します。未指定の場合、CLIは以下の場所で\_keeper.ini\_を探します。

* 環境変数 **`KSM_INI_DIR`** で定義されたパス
* カレントディレクトリ
* ユーザーのホームディレクトリ
  * `${HOME}`
  * `${HOME}/.config/ksm`
  * `$env:USERPROFILE`
* 各種システムディレクトリ
  * `/etc`
  * `/etc/ksm`
  * `/etc/keeper`
  * `$env:APPDATA/Keeper`
  * `$env:ProgramData/Keeper`
  * `$env:ProgramFiles/Keeper`

`-p, --profile-name <名前>` 指定した構成プロファイルを使用します。

`-o, --output <{stdout, stderr, filename}>` 出力先を設定します。

* `stdout` — 標準出力（既定）
* `stderr` — 標準エラー
* `<filename>` — 指定したテキストファイルへ出力

`--color/--no-color`, `-c/-nc` 出力の色を有効または無効にします。

`--cache/--no-cache` このコマンド実行でのレコードキャッシュの使用を有効または無効にします。

### キーリング構成の削除 <a href="#deleting-keyring-configuration" id="deleting-keyring-configuration"></a>

システムのセキュアストレージからKSM構成を完全に削除するには、OSに応じた手順に従います。

#### macOS（キーチェーン） <a href="#macos-keychain" id="macos-keychain"></a>

**キーチェーンアクセスアプリを使う場合:**

1. **キーチェーンアクセス**を開きます（アプリケーション → ユーティリティ → キーチェーンアクセス）
2. 検索ボックスに `KSM-cli` と入力します
3. 一致する項目をすべて選択します
4. 右クリックして **削除** を選びます

**コマンドラインを使う場合:**

```
# List KSM entries
security find-generic-password -s "KSM-cli" 2>/dev/null

# Delete specific entries (repeat for each profile)
security delete-generic-password -s "KSM-cli" -a "ksm-cli-common"
security delete-generic-password -s "KSM-cli" -a "ksm-cli-common-integrity"
security delete-generic-password -s "KSM-cli" -a "ksm-cli-profile-_default"
security delete-generic-password -s "KSM-cli" -a "ksm-cli-profile-_default-integrity"
security delete-generic-password -s "KSM-cli" -a "ksm-cli-profile-<profile_name>"
security delete-generic-password -s "KSM-cli" -a "ksm-cli-profile-<profile_name>-integrity"
```

#### Windows（資格情報マネージャー） <a href="#windows-credential-manager" id="windows-credential-manager"></a>

**資格情報マネージャーの UI:**

1. **コントロールパネル** → **ユーザーアカウント** → **資格情報マネージャー** を開きます
2. **Windows の資格情報** をクリックします
3. `KSM-cli` で始まる項目を探します
4. 各項目を開き、**削除** を選びます

**コマンドライン（PowerShell）:**

```
# List credentials
cmdkey /list | Select-String "KSM-cli"

# Delete specific credentials
cmdkey /delete:KSM-cli:ksm-cli-common
cmdkey /delete:KSM-cli:ksm-cli-common-integrity
cmdkey /delete:KSM-cli:ksm-cli-profile-_default
cmdkey /delete:KSM-cli:ksm-cli-profile-_default-integrity
cmdkey /delete:KSM-cli:ksm-cli-profile-<profile_name>
cmdkey /delete:KSM-cli:ksm-cli-profile-<profile_name>-integrity
```

**コマンドライン（CMD）:**

```cmd
cmdkey /delete:KSM-cli:ksm-cli-common
cmdkey /delete:KSM-cli:ksm-cli-common-integrity
cmdkey /delete:KSM-cli:ksm-cli-profile-_default
cmdkey /delete:KSM-cli:ksm-cli-profile-_default-integrity
```

#### Linux（Secret Service / GNOME Keyring） <a href="#linux-secret-service--gnome-keyring" id="linux-secret-service--gnome-keyring"></a>

**Seahorse（GNOME Keyring の GUI）:**

1. **パスワードと鍵**（Seahorse）を開きます
2. **ログイン** キーリングを確認します
3. `KSM-cli` を含む項目を検索します
4. 各項目を右クリックして削除します

**secret-tool（コマンドライン）:**

```
# Search for KSM entries
secret-tool search service KSM-cli 2>/dev/null

# Delete entries
secret-tool clear service KSM-cli username ksm-cli-common
secret-tool clear service KSM-cli username ksm-cli-common-integrity
secret-tool clear service KSM-cli username ksm-cli-profile-_default
secret-tool clear service KSM-cli username ksm-cli-profile-_default-integrity
secret-tool clear service KSM-cli username ksm-cli-profile-<profile_name>
secret-tool clear service KSM-cli username ksm-cli-profile-<profile_name>-integrity
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/jp/keeperpam/secrets-manager/secrets-manager-command-line-interface.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
