更新时间:2024-04-17 GMT+08:00

初始化配置

使用obsutil之前,您需要配置obsutil与OBS的对接信息,包括OBS终端节点地址(Endpoint)和访问密钥(AK和SK)。获得OBS的认证后,才能使用obsutil执行OBS桶和对象的相关操作。

前提条件

配置方法

您可以通过config命令对obsutil进行初始化配置(关于config的详细介绍,参见更新配置文件),示例如下:

  • Windows操作系统

    使用永久AK、SK进行初始化配置(token无需填写,回车跳过即可):

    obsutil config -interactive
    
    Please input your ak:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your sk:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your endpoint:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your token:
    
    Config file url:
      C:\Users\tools\.obsutilconfig
    
    Update config file successfully!

    使用临时AK、SK、SecurityToken进行初始化配置:

    obsutil config -interactive
    
    Please input your ak:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your sk:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your endpoint:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your token:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    
    Config file url:
      C:\Users\tools\.obsutilconfig
    
    Update config file successfully!
  • macOS/Linux操作系统

    使用永久AK、SK进行初始化配置(token无需填写,回车跳过即可):

    ./obsutil config -interactive
    
    Please input your ak:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your sk:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your endpoint:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your token:
    
    Config file url:
      /root/.obsutilconfig
    
    Update config file successfully!

    使用临时AK、SK、SecurityToken进行初始化配置:

    ./obsutil config -interactive
    
    Please input your ak:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your sk:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your endpoint:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    Please input your token:
    xxxxxxxxxxxxxxxxxxxxxxxxx
    
    Config file url:
      /root/.obsutilconfig
    
    Update config file successfully!
  • 以上命令运行后,会在运行obsutil命令的用户目录(macOS/Linux操作系统的“~”目录;Windows操作系统的“C:\Users\<username>”目录。)下自动生成一个名为.obsutilconfig的配置文件,它包含了obsutil的所有配置信息。
  • .obsutilconfig的配置文件中的详细配置参数说明请参见配置参数说明
  • .obsutilconfig文件中保存有用户的AK和SK等信息,为避免密钥泄露,.obsutilconfig默认为隐藏文件,您可以在运行obsutil命令的用户目录下通过使用以下命令查看到该文件:
    • Windows操作系统
      dir 
    • macOS/Linux操作系统
      ls -a 

      ls -al
  • obsutil会对.obsutilconfig文件中的AK和SK进行加密以保护密钥安全。

检查连通性

配置完成后,您可以通过如下方式检查连通性,确认配置是否无误。

  • Windows操作系统
    obsutil ls -s
  • macOS/Linux操作系统
    ./obsutil ls -s

根据命令回显结果,检查配置结果:

  • 如果返回结果中包含“Bucket number :”,表明配置正确。
  • 如果返回结果中包含“Http status [403]”,表明访问密钥配置有误。
  • 如果返回结果中包含“A connection attempt failed”,表明无法连接OBS服务,请检查网络环境是否正常。

如果返回结果中包含“Http status [403]”,也可能是没有获取桶列表的权限,需要视具体场景进一步确认根因。