全部產品
Search
文件中心

CloudSSO:使用CLI登入雲SSO並訪問阿里雲資源

更新時間:Jul 23, 2025

雲SSO已與阿里雲CLI進行了整合。使用者除了使用瀏覽器登入雲SSO使用者門戶,也可以通過阿里雲CLI登入。登入後,選擇對應RD帳號和許可權,通過CLI命令列訪問阿里雲資源。本文為您介紹雲SSO使用者使用阿里雲CLI登入雲SSO的操作方法。

背景資訊

阿里雲CLI 3.0.271及以上版本(新版本)新增CloudSSO憑證類型並簡化了配置流程,舊版本操作方法仍然可用。您可使用aliyun version命令查看阿里雲CLI目前的版本。

新版本

新版本提供互動式與非互動式兩種配置方式。互動式配置方式通過流程引導簡化了操作,便於使用者快速上手;非互動式配置方式更適用於指令碼編寫,便於實現自動化配置。

互動式配置

  1. 執行aliyun configure命令,開始以互動式方式配置雲SSO登入資訊。您可以設定多個Profile,通過指定Profile快速切換登入的帳號和訪問配置。

    aliyun configure --profile SSOProfile --mode CloudSSO
  2. 根據提示輸入使用者登入地址。

    aliyun configure --profile SSOProfile --mode CloudSSO
    CloudSSO Sign In Url []: https://signin-******.alibabacloudsso.com/device/login
  3. 在彈出的瀏覽器視窗中,根據介面提示,完成雲SSO使用者登入,登入成功後請關閉瀏覽器視窗。

    如果瀏覽器視窗未彈出,您可以根據CLI的提示資訊,手動複製登入URL(SignIn url)和使用者碼(User code)完成登入。

    提示資訊樣本:

    If the browser does not open automatically, use the following URL to complete the login process:
    
    SignIn url: https://signin-****.alibabacloudsso.com/device/code
    User code: *********
  4. CLI返回登入成功,同時列出您可以訪問的RD帳號名稱,請輸入編號選擇要訪問的RD帳號。

    Now you can login to your account with SSO configuration in the browser.
    You have successfully logged in.
    Please choose an account:
    1. <RD Management Account>
    2. AccountName
    Please input the account number: 1
  5. CLI列出您可以使用的訪問配置,請輸入編號選擇要使用的訪問配置。

    Please choose an access configuration:
    1. AccessConfiguration1
    2. AccessConfiguration2
    Please input the access configuration number: 2
  6. 指定預設地區。

    Default Region Id []: cn-hangzhou
  7. 配置成功後顯示Configure Done字樣及歡迎資訊。

非互動式配置

執行aliyun configure set命令可通過非互動式方式配置CloudSSO憑證,憑證所需參數及對應選項如下表所示:

選項

說明

樣本值

profile

憑證配置名稱。

該名稱可由使用者自訂,支援傳入大寫英文字母(A-Z)、小寫英文字母(a-z)、數字(0-9)及特殊字元( _/+=.@-)。

SSOProfile

mode

憑證類型。

當前情境中傳入值必須為CloudSSO

CloudSSO

cloud-sso-sign-in-url

使用者登入地址。

擷取方法:請登入雲SSO控制台,在概覽頁面的右側,擷取使用者登入URL。

https://signin-******.alibabacloudsso.com/device/login

cloud-sso-account-id

RD帳號UID。

擷取方法:請登入雲SSO控制台,在多帳號許可權管理頁面的右側,擷取RD帳號UID。

012345678910****

cloud-sso-access-config

訪問配置ID。

擷取方法:請登入雲SSO控制台,在訪問配置頁面,擷取訪問配置ID。

ac-012345678910abcde****

region

預設地區

部分雲產品不支援跨地區訪問,建議您優先將預設地區設定為已購資源所在地區。

cn-hangzhou

配置命令樣本如下:

aliyun configure set \
  --profile SSOProfile \
  --mode CloudSSO \
  --cloud-sso-sign-in-url "https://signin-******.alibabacloudsso.com/device/login" \
  --cloud-sso-account-id "012345678910****" \
  --cloud-sso-access-config "ac-012345678910abcde****" \ 
  --region "cn-hangzhou"
aliyun configure set `
  --profile SSOProfile `
  --mode CloudSSO `
  --cloud-sso-sign-in-url "https://signin-******.alibabacloudsso.com/device/login" `
  --cloud-sso-account-id "012345678910****" `
  --cloud-sso-access-config "ac-012345678910abcde****" `
  --region "cn-hangzhou"
說明

使用非互動式方式配置CloudSSO憑證後,首次使用該憑證需通過aliyun configure --profile <profileName>命令執行登入操作。

舊版本

操作步驟

步驟一:安裝CLI

您需要安裝阿里雲CLI和雲SSO CLI,具體如下:

步驟二:配置雲SSO登入資訊

  1. 執行以下命令,開始配置雲SSO登入資訊。

    acs-sso configure
  2. 輸入使用者登入地址signinUrl

    說明

    使用者登入地址signinUrl擷取方法:請登入雲SSO控制台,在概覽頁面的右側,擷取使用者登入URL

    請求樣本:

    acs-sso configure
    ? please input 'signinUrl': https://signin-******.alibabacloudsso.com/device/login

    配置成功的返回樣本:

    configuration done!

步驟三:雲SSO使用者登入阿里雲

常用命令如下:

  • 預設登入

    1. 執行以下命令,開始登入。

      acs-sso login
    2. 在彈出的瀏覽器視窗中,根據介面提示,完成雲SSO使用者登入,登入成功後請關閉瀏覽器視窗。

      如果瀏覽器視窗未彈出,您可以根據CLI的提示資訊,手動複製登入URL(SignIn url)和使用者碼(User code)完成登入。

      提示資訊樣本:

      If your default browser is not opened automatically, please use the following URL to finish the signin process.
      Signin URL: https://signin-****.alibabacloudsso.com/device/code
      User Code: *********
    3. 如果目前使用者被授予了多個RD帳號的存取權限,CLI會互動式地提醒您選擇要使用的RD帳號和訪問配置,並最終產生相應的阿里雲存取金鑰。

      返回樣本:

      You have logged in.
      used account: test-account(191585963325****)
      used access configuration: TestAC(ac-x08xz11covd3cyzd****)
      {
        "mode": "StsToken",
        "access_key_id": "STS.****",
        "access_key_secret": "****",
        "sts_token": "****"
      }

    登入成功後,profile會綁定該RD帳號和訪問配置。下次登入時,將會使用本次緩衝的RD帳號和訪問配置直接登入。

  • 指定雲SSO的登入配置名稱

    acs-sso login --profile sso

    當您想同時配置多個RD帳號和訪問配置所對應的SSO登入資訊時,可以通過指定登入配置名稱來區分。您可以使用--profile指定雲SSO的不同登入配置名稱。上述命令表示指定使用的登入配置名稱是sso。

    不指定--profile時,預設使用的登入配置名稱是default。

  • 擷取登入配置列表

    acs-sso profile --list
  • 刪除指定的登入配置

    執行以下命令,刪除預設登入配置。

    acs-sso profile --delete --profile default

    執行以下命令,刪除名為sso的登入配置。

    acs-sso profile --delete --profile sso
  • 配置輸出模式

    以下兩種方式,您可以任選其一進行配置:

    • 外部進程模式(預設):當您與阿里雲CLI的外部進程(External)模式配合使用時,您可以使用該輸出模式。

      返回樣本:

      {
        "mode": "StsToken",
        "access_key_id": "STS.NUyPeEoab****",
        "access_key_secret": "GBubpmh****",
        "sts_token": "CAIS****"
      }
    • 環境變數模式:您可以使用--env 參數配置返回結果為環境變數模式。例如:acs-sso login --profile user1 --env

      返回樣本:

      export ALIBABACLOUD_ACCESS_KEY_ID=STS.NUyPeEoab****
      export ALIBABACLOUD_ACCESS_KEY_SECRET=GBubpmh****
      export SECURITY_TOKEN=CAIS****

      環境變數可以與阿里雲的相關工具(例如:Terraform等)配合使用。例如:`acs-sso login --profile user1 --env` && terraform plan

      環境變數也可以與阿里雲CLI配合使用。例如:`acs-sso login --profile user1 --env` && aliyun ecs DescribeRegions

步驟四:配合阿里雲CLI使用

請求樣本:

aliyun configure --mode External --profile sso
Configuring profile 'sso' in 'External' authenticate mode...
Process Command []: acs-sso login --profile sso
Default Region Id []: cn-shanghai
Default Output Format [json]: json (Only support json)
Default Language [zh|en] en: 
Saving profile[sso] ...Done.

其中,Process Command使用命令acs-sso login --profile sso指定雲SSO的登入配置名稱為sso。建議您在阿里雲CLI和雲SSO CLI指定相同的配置名稱,這樣當有多個雲SSO登入配置時,可以多次配置CLI憑證,並匹配不同的雲SSO登入配置。

配置成功的返回樣本:

Configure Done!!!
..............888888888888888888888 ........=8888888888888888888D=..............
...........88888888888888888888888 ..........D8888888888888888888888I...........
.........,8888888888888ZI: ...........................=Z88D8888888888D..........
.........+88888888 ..........................................88888888D..........
.........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
.........+88888888 ............. ************* ..............O8888888D..........
.........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
.........+88888888...........................................88888888D..........
..........D888888888888DO+. ..........................?ND888888888888D..........
...........O8888888888888888888888...........D8888888888888888888888=...........
............ .:D8888888888888888888.........78888888888888888888O ..............

執行以下測試樣本,驗證阿里雲CLI是否可用。

aliyun sts GetCallerIdentity --profile sso