View a markdown version of this page

CLI 命令語法 - AWS Client VPN

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

CLI 命令語法

您可以使用下列語法來使用 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

說明

建立與設定檔的 VPN 連線。

概要

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

選項

--profile-name (string)

要連線的設定檔名稱。此選項為必要。

--auth-user-pass (string)

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

範例

範例:連線至 VPN 設定檔

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

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

輸出:

{
  "status": "Connected"
}

中斷連線

說明

終止作用中的 VPN 連接。

概要

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

選項

--profile-name (string)

要中斷連接的設定檔名稱。此選項為必要。

範例

範例:中斷 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

說明

匯入 VPN 連線設定檔。

概要

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

選項

--profile-name (string)

匯入設定檔的自訂名稱。此選項為必要。

--config-path (string)

OpenVPN 組態檔案 (.ovpn) 的路徑。此選項為必要。

--global (布林值)

匯入為可供所有使用者使用的全域設定檔。此選項需要管理員權限。

範例

範例:匯入設定檔

下列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

說明

從用戶端刪除設定檔。

概要

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

選項

--profile-name (string)

要刪除的設定檔名稱。此選項為必要。

範例

範例:刪除設定檔

下列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

說明

列出所有 VPN 設定檔。

概要

aws-vpn-client list-profiles

範例

範例:列出所有 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

說明

擷取設定檔的 OpenVPN 組態。

概要

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

選項

--profile-name (string)

要擷取組態的設定檔名稱。此選項為必要。

範例

範例:擷取 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

說明

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

概要

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

選項

--profile-name (string)

要擷取其連線狀態的設定檔名稱。此選項為必要。

--show-details (布林值)

在輸出中包含連線位元組統計資料。

範例

範例:取得連線狀態

下列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

說明

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

概要

aws-vpn-client list-connections

範例

範例:列出作用中連線

下列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

說明

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

概要

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

選項

--key (string)

要設定的偏好設定金鑰名稱。此選項為必要。

--value (string)

要為偏好設定索引鍵設定的值。此選項為必要。

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

enable-telemetry

啟用或停用遙測 (true/false)。

enable-user-profile-management

允許或拒絕最終使用者匯入或刪除設定檔 (true/false)。

max-connections

並行連線數目上限 (整數,1-5)。

範例

範例:設定偏好設定

下列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

說明

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

概要

aws-vpn-client list-preferences

範例

範例:列出所有偏好設定

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

aws-vpn-client list-preferences

輸出:

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

send-diagnostic-logs

說明

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

概要

aws-vpn-client send-diagnostic-logs

範例

範例:傳送診斷日誌

下列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值。

結束代碼

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

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