- 文档首页
对象存储
工具指南
TOS 命令行工具
配置 ve-tos-cli 统一凭证
TOS 命令行工具
配置 ve-tos-cli 统一凭证
配置 ve-tos-cli 统一凭证
本文主要介绍如何为 ve-tos-cli 配置统一访问凭证。ve-tos-cli 支持使用 ve 管理的统一凭证访问 TOS。完成配置后,无需在 ve-tos-cli 中单独配置 AK/SK。该功能适用于需要在多工具间共享统一凭证、自动化任务中避免硬编码 AK/SK、跨环境统一管理访问凭证等场景。
- ve login 获取的是临时凭证。凭证失效后,请重新执行 ve login。
- 使用非 default profile 登录后,需要执行 ve configure profile --profile <profile-name> 切换当前 profile,或在调用 ve-tos-cli 时通过 --profile 显式指定。
- ve-tos-cli 使用统一凭证模式时,会忽略其本地配置中的 AK/SK,不会将本地 AK/SK 作为回退凭证。
- 请勿将本地凭证配置文件提交到代码仓库,也不要在日志或脚本中输出凭证内容。
- 执行自动化任务前,建议先运行 ve sts GetCallerIdentity 和 ve-tos-cli ls,确认登录状态与访问权限正常。
- 执行 ve login,登录火山引擎账号并在本地生成临时身份凭证。
- 执行 ve-tos-cli config set auth_mode unified,将 ve-tos-cli 的认证模式设置为统一凭证模式。
- 执行 ve login 命令,使用默认 profile 登录。
- ve login 使用 OAuth 2.0 设备码授权。命令执行后,终端会显示登录地址和用户码,并尝试自动打开浏览器。
- 在浏览器中完成授权后,ve 会将临时身份凭证保存到本地。默认情况下,认证信息写入 ~/.volcengine/config.json 文件中。
- 如果当前设备无法打开浏览器,例如无图形界面的远程服务器或容器,请执行 ve login --no-browser 命令,然后在其他设备上打开终端显示的登录地址,输入用户码并完成授权。授权期间请勿终止当前命令,ve 会持续轮询登录结果。
- 如需指定 profile 和地域,请执行 ve login --profile dev --region cn-beijing 命令。
- cn-beijing 需替换为您所需的地域,关于 --region 参数支持的地域列表,请参见地域和访问域名。
- 使用非 default profile 登录后,需执行 ve configure profile --profile dev 命令将其切换为当前 profile。
- 登录完成后,执行 ve sts GetCallerIdentity 命令验证身份。
- 执行 ve-tos-cli config set auth_mode unified 命令,将 ve-tos-cli 的认证模式设置为统一凭证模式。
- 配置完成后,ve-tos-cli 会使用 ve 管理的统一凭证,不再要求单独写入 AK/SK。
- 执行 ve-tos-cli config show --output json 命令查看当前配置。
- 确认输出中的 auth_mode 为 unified。
- 执行 ve-tos-cli ls 命令,列举 TOS 资源。
- 执行 ve-tos-cli ls tos://<bucket-name>/<prefix>/ 命令列举指定存储桶或目录中的对象。
- 命令中的 <bucket-name> 替换为实际的存储桶名称,<prefix> 替换为目标目录前缀。如果无需指定目录,可以省略 <prefix>/ 部分。
- 执行 ve-tos-cli ls tos://<bucket-name>/<prefix>/ --output table 命令,以表格形式显示结果。
命令正常返回结果,表示 ve-tos-cli 已成功使用统一凭证访问 TOS。
ve-tos-cli config set auth_mode unified
ve sts GetCallerIdentity
ve login --profile dev --region cn-beijing
# 将该 profile 设置为当前 profile
ve configure profile --profile dev
ve-tos-cli config set auth_mode unified
ve-tos-cli --profile dev ls
使用统一凭证模式时,ve 与 ve-tos-cli 应使用同名 profile。否则,ve-tos-cli 可能无法读取预期的登录状态。
配置说明:
ve sts GetCallerIdentity
ve-tos-cli config set auth_mode unified
ve-tos-cli config show --output json
- 确认 ve 已登录,且 auth_mode 为 unified。
- 使用自定义 profile 后无法访问 TOS。
- 确认 ve 与 ve-tos-cli 使用同名 profile:
ve configure profile --profile dev
ve-tos-cli --profile dev ls
- 在其他可访问浏览器的设备上打开终端显示的地址并输入用户码,即可完成授权。
ve logout --profile dev
# 退出所有通过 ve login 创建的登录状态
- 退出后,使用统一凭证模式的 ve-tos-cli 将无法继续访问 TOS。如需恢复访问,请重新执行 ve login。
最近更新时间:2026.10.10 16:47:34