

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# CLI 命令語法
<a name="cli-command-syntax"></a>

您可以使用下列語法來使用 CLI 命令：

```
aws-vpn-client <COMMAND> [OPTIONS]
```

CLI 工具支援下列命令。

```
Usage: aws-vpn-client <COMMAND>

Commands:
  connect                Connect a profile through the AWS VPN Client
  disconnect             Disconnect a profile from the AWS VPN Client
  delete-profile         Delete a profile from the AWS VPN Client
  import-profile         Import a VPN connection profile
  list-profiles          List all VPN profiles
  get-config             Get configuration for a profile
  put-preference         Put a preference value
  list-preferences       List all preferences
  get-connection-status  Get the current connection status for a VPN profile
  list-connections       List all active VPN connections
  send-diagnostic-logs   Send diagnostic logs to AWS for troubleshooting
  help                   Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version
```

## connect
<a name="cli-cmd-connect"></a>

### 說明
<a name="cli-cmd-connect-description"></a>

建立與設定檔的 VPN 連線。

### 概要
<a name="cli-cmd-connect-synopsis"></a>

```
aws-vpn-client connect
  --profile-name <PROFILE>
  [--auth-user-pass <AUTH_USER_PASS>]
```

### 選項
<a name="cli-cmd-connect-options"></a>

`--profile-name` (string)  
要連線的設定檔名稱。此選項為必要。

`--auth-user-pass` (string)  
包含使用者名稱 （第 1 行）、密碼 （第 2 行） 和選用 MFA 代碼 （第 3 行） 的檔案路徑。此選項並非必要。

### 範例
<a name="cli-cmd-connect-examples"></a>

**範例：連線至 VPN 設定檔**

下列`connect`範例會建立與設定檔的 VPN 連線。

```
aws-vpn-client connect --profile-name "Production-VPN"
```

輸出：

```
{
  "status": "Connected"
}
```

## 中斷連線
<a name="cli-cmd-disconnect"></a>

### 說明
<a name="cli-cmd-disconnect-description"></a>

終止作用中的 VPN 連接。

### 概要
<a name="cli-cmd-disconnect-synopsis"></a>

```
aws-vpn-client disconnect
  --profile-name <PROFILE_NAME>
```

### 選項
<a name="cli-cmd-disconnect-options"></a>

`--profile-name` (string)  
要中斷連接的設定檔名稱。此選項為必要。

### 範例
<a name="cli-cmd-disconnect-examples"></a>

**範例：中斷 VPN 設定檔的連線**

下列`disconnect`範例會終止 VPN 連線。成功時沒有輸出。

```
aws-vpn-client disconnect --profile-name "Production-VPN"
```

**範例：中斷連線錯誤**

下列`disconnect`範例顯示未連接設定檔時的錯誤。

```
aws-vpn-client disconnect --profile-name "Production-VPN"
```

輸出：

```
{
  "status": "Error",
  "message": "Profile is not connected"
}
```

## import-profile
<a name="cli-cmd-import-profile"></a>

### 說明
<a name="cli-cmd-import-profile-description"></a>

匯入 VPN 連線設定檔。

### 概要
<a name="cli-cmd-import-profile-synopsis"></a>

```
aws-vpn-client import-profile
  --profile-name <PROFILE_NAME>
  --config-path <CONFIG_PATH>
  [--global]
```

### 選項
<a name="cli-cmd-import-profile-options"></a>

`--profile-name` (string)  
匯入設定檔的自訂名稱。此選項為必要。

`--config-path` (string)  
OpenVPN 組態檔案 (.ovpn) 的路徑。此選項為必要。

`--global` （布林值）  
匯入為可供所有使用者使用的全域設定檔。此選項需要管理員權限。

### 範例
<a name="cli-cmd-import-profile-examples"></a>

**範例：匯入設定檔**

下列`import-profile`範例會匯入 VPN 連線設定檔。

```
aws-vpn-client import-profile --profile-name "Production-VPN" --config-path /path/to/vpn-config.ovpn
```

輸出：

```
{
  "status": "Success"
}
```

**範例：匯入全域設定檔**

下列`import-profile`範例會匯入全域設定檔。這需要管理員權限。

```
sudo aws-vpn-client import-profile --profile-name "Company-VPN" --config-path /path/to/config.ovpn --global
```

輸出：

```
{
  "status": "Success"
}
```

**範例：使用無效的檔案路徑匯入錯誤**

下列`import-profile`範例顯示找不到組態檔案時的錯誤。

```
aws-vpn-client import-profile --profile-name "test" --config-path /invalid/path.ovpn
```

輸出：

```
{
  "status": "Error",
  "message": "Failed to read OpenVPN config file: No such file or directory (os error 2)"
}
```

## delete-profile
<a name="cli-cmd-delete-profile"></a>

### 說明
<a name="cli-cmd-delete-profile-description"></a>

從用戶端刪除設定檔。

### 概要
<a name="cli-cmd-delete-profile-synopsis"></a>

```
aws-vpn-client delete-profile
  --profile-name <PROFILE_NAME>
```

### 選項
<a name="cli-cmd-delete-profile-options"></a>

`--profile-name` (string)  
要刪除的設定檔名稱。此選項為必要。

### 範例
<a name="cli-cmd-delete-profile-examples"></a>

**範例：刪除設定檔**

下列`delete-profile`範例會刪除 VPN 設定檔。成功時沒有輸出。

```
aws-vpn-client delete-profile --profile-name "Production-VPN"
```

**範例：使用不存在的設定檔刪除錯誤**

下列`delete-profile`範例顯示設定檔不存在時的錯誤。

```
aws-vpn-client delete-profile --profile-name "nonexistent"
```

輸出：

```
{
  "status": "Error",
  "message": "Profile not found"
}
```

## list-profiles
<a name="cli-cmd-list-profiles"></a>

### 說明
<a name="cli-cmd-list-profiles-description"></a>

列出所有 VPN 設定檔。

### 概要
<a name="cli-cmd-list-profiles-synopsis"></a>

```
aws-vpn-client list-profiles
```

### 範例
<a name="cli-cmd-list-profiles-examples"></a>

**範例：列出所有 VPN 設定檔**

下列`list-profiles`範例列出所有匯入的 VPN 設定檔。

```
aws-vpn-client list-profiles
```

輸出：

```
[
  {
    "profile-name": "Production-VPN",
    "owned-by": "jdoe",
    "auth-type": "saml",
    "imported-at": "2026-07-21T13:04:42-07:00"
  },
  {
    "profile-name": "Staging-VPN",
    "owned-by": "jdoe",
    "auth-type": "ma",
    "imported-at": "2026-07-22T10:30:00-07:00"
  }
]
```

**注意**  
全域設定檔 （使用 匯入`--global`) 沒有 `owned-by` 欄位。

## get-config
<a name="cli-cmd-get-config"></a>

### 說明
<a name="cli-cmd-get-config-description"></a>

擷取設定檔的 OpenVPN 組態。

### 概要
<a name="cli-cmd-get-config-synopsis"></a>

```
aws-vpn-client get-config
  --profile-name <PROFILE_NAME>
```

### 選項
<a name="cli-cmd-get-config-options"></a>

`--profile-name` (string)  
要擷取組態的設定檔名稱。此選項為必要。

### 範例
<a name="cli-cmd-get-config-examples"></a>

**範例：擷取 OpenVPN 組態**

下列`get-config`範例會擷取設定檔的 OpenVPN 組態。

```
aws-vpn-client get-config --profile-name "Production-VPN"
```

輸出：

```
client
dev tun
proto udp
remote cvpn-endpoint-0123456789abcdef0.prod.clientvpn.us-east-1.amazonaws.com 443
remote-random-hostname
resolv-retry infinite
nobind
remote-cert-tls server
cipher AES-256-GCM
verb 3
<ca>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</ca>
auth-user-pass
reneg-sec 0
```

## get-connection-status
<a name="cli-cmd-get-connection-status"></a>

### 說明
<a name="cli-cmd-get-connection-status-description"></a>

取得 VPN 設定檔的目前連線狀態。

### 概要
<a name="cli-cmd-get-connection-status-synopsis"></a>

```
aws-vpn-client get-connection-status
  --profile-name <PROFILE_NAME>
  [--show-details]
```

### 選項
<a name="cli-cmd-get-connection-status-options"></a>

`--profile-name` (string)  
要擷取其連線狀態的設定檔名稱。此選項為必要。

`--show-details` （布林值）  
在輸出中包含連線位元組統計資料。

### 範例
<a name="cli-cmd-get-connection-status-examples"></a>

**範例：取得連線狀態**

下列`get-connection-status`範例會擷取設定檔的連線狀態。

```
aws-vpn-client get-connection-status --profile-name "Production-VPN"
```

輸出：

```
{
  "connection-status": "Connected",
  "latest-connection-attempt": {
    "initiated-by": "jdoe",
    "updated-at": "2026-07-24T15:50:36-07:00"
  }
}
```

**範例：取得包含詳細資訊的連線狀態**

下列`get-connection-status`範例使用 `--show-details`選項包含位元組統計資料。

```
aws-vpn-client get-connection-status --profile-name "Production-VPN" --show-details
```

輸出：

```
{
  "connection-status": "Connected",
  "latest-connection-attempt": {
    "initiated-by": "jdoe",
    "updated-at": "2026-07-24T15:50:36-07:00",
    "details": {
      "tunnel-bytes-in": 0,
      "tunnel-bytes-out": 0,
      "transport-bytes-in": 9674,
      "transport-bytes-out": 11413
    }
  }
}
```

## list-connections
<a name="cli-cmd-list-connections"></a>

### 說明
<a name="cli-cmd-list-connections-description"></a>

列出所有作用中的 VPN 連線。

### 概要
<a name="cli-cmd-list-connections-synopsis"></a>

```
aws-vpn-client list-connections
```

### 範例
<a name="cli-cmd-list-connections-examples"></a>

**範例：列出作用中連線**

下列`list-connections`範例列出所有作用中的 VPN 連線。

```
aws-vpn-client list-connections
```

輸出：

```
[
  {
    "profile-name": "Production-VPN",
    "initiated-by": "jdoe",
    "connection-status": "Connected",
    "last-updated-at": "2026-07-24T15:50:36-07:00"
  }
]
```

**範例：無作用中連線**

下列`list-connections`範例顯示沒有作用中連線時的輸出。

```
aws-vpn-client list-connections
```

輸出：

```
[]
```

## put-preference
<a name="cli-cmd-put-preference"></a>

### 說明
<a name="cli-cmd-put-preference-description"></a>

設定全域組態偏好設定。大多數設定需要管理員權限。

### 概要
<a name="cli-cmd-put-preference-synopsis"></a>

```
aws-vpn-client put-preference
  --key <PREFERENCE_KEY>
  --value <PREFERENCE_VALUE>
```

### 選項
<a name="cli-cmd-put-preference-options"></a>

`--key` (string)  
要設定的偏好設定金鑰名稱。此選項為必要。

`--value` (string)  
要為偏好設定索引鍵設定的值。此選項為必要。

下列偏好設定索引鍵可供使用：

`enable-telemetry`  
啟用或停用遙測 (true/false)。

`enable-user-profile-management`  
允許或拒絕最終使用者匯入或刪除設定檔 (true/false)。

`max-connections`  
並行連線數目上限 （整數，1-5)。

### 範例
<a name="cli-cmd-put-preference-examples"></a>

**範例：設定偏好設定**

下列`put-preference`範例會設定連線數量上限。這需要管理員權限。成功時沒有輸出。

```
sudo aws-vpn-client put-preference --key max-connections --value 4
```

**範例：沒有管理員權限的錯誤**

下列`put-preference`範例顯示當您在沒有管理員權限的情況下執行 命令時的錯誤。

```
aws-vpn-client put-preference --key max-connections --value 4
```

輸出：

```
{
  "status": "Error",
  "message": "Permission denied: admin privileges required"
}
```

**範例：值無效的錯誤**

下列`put-preference`範例顯示您提供無效值時的錯誤。

```
sudo aws-vpn-client put-preference --key max-connections --value 8
```

輸出：

```
{
  "status": "Error",
  "message": "Preference value is invalid"
}
```

## list-preferences
<a name="cli-cmd-list-preferences"></a>

### 說明
<a name="cli-cmd-list-preferences-description"></a>

顯示所有全域組態偏好設定和目前值。

### 概要
<a name="cli-cmd-list-preferences-synopsis"></a>

```
aws-vpn-client list-preferences
```

### 範例
<a name="cli-cmd-list-preferences-examples"></a>

**範例：列出所有偏好設定**

下列`list-preferences`範例會顯示所有全域組態偏好設定及其目前值。

```
aws-vpn-client list-preferences
```

輸出：

```
{
  "enable-telemetry": true,
  "enable-user-profile-management": true,
  "max-connections": 1
}
```

## send-diagnostic-logs
<a name="cli-cmd-send-diagnostic-logs"></a>

### 說明
<a name="cli-cmd-send-diagnostic-logs-description"></a>

收集診斷日誌並將其提交至 AWS 以進行故障診斷。

### 概要
<a name="cli-cmd-send-diagnostic-logs-synopsis"></a>

```
aws-vpn-client send-diagnostic-logs
```

### 範例
<a name="cli-cmd-send-diagnostic-logs-examples"></a>

**範例：傳送診斷日誌**

下列`send-diagnostic-logs`範例會收集診斷日誌並將其提交至 AWS。

```
aws-vpn-client send-diagnostic-logs
```

輸出：

```
{
  "reference-id": "us-west-2:78ff6531-5dc4-c706-7149-e6cfd8adadc7/2026-07-24-16-03-55.zip"
}
```

**注意**  
在報告問題時與 AWS Support 共用該`reference-id`值。

## 結束代碼
<a name="cli-cmd-exit-codes"></a>

 AWS Client VPN CLI 工具會傳回下列結束代碼。


| 結束程式碼 | 意義 | 
| --- | --- | 
| 0 | 成功 | 
| 1 | 一般錯誤 | 
| 2 | 無效的命令語法 | 