This topic describes how to configure ossutil.
Version upgrade
We recommend using the newly upgraded ossutil 2.0. For quick installation and usage, see Install ossutil.
Key features of ossutil 2.0 include the following:
-
A new command organization structure that introduces multi-level command support, including API-level commands (such as
ossutil api put-bucket-acl
) and advanced commands (such asossutil config
). -
An improved configuration management mechanism that simplifies the initial configuration process. After installation, users only need to provide the AccessKey ID, AccessKey Secret, and region ID to complete the basic configuration. It also supports specifying multiple configuration files through the
--profile
parameter, enhancing flexibility. -
Rich filtering parameters for batch processing commands (such as
ls
,cp
,rm
, etc.), with new support for multiple filter conditions based on path, file size, modification time, and object metadata to greatly improve the precision and efficiency of operations. -
Flexible output format adjustment by adding the
--output-format
parameter, allowing users to set the output format to JSON, YAML, or XML to better adapt to different data processing needs. It also introduces the--output-query
option, enabling users to filter the output content to obtain the required information. -
Security enhancement by supporting the setting of sensitive parameters through environment variables to avoid directly exposing keys in the command line, reducing the risk of leaks. Additionally, the new
--dry-run
option allows users to verify the behavior of commands before actual execution, ensuring correct operations.
Quick configuration using the config command
In most cases, you can quickly set up your ossutil tool using the config command, which provides an interactive way to generate configuration files.
The following example shows how to configure ossutil on the Linux operating system.
-
Enter the configuration command.
ossutil config
-
Set the configuration file path as prompted.
You can specify the path of the configuration file based on your business requirements. By default, the configuration file is saved to the ~/.ossutilconfig file. Press Enter to use the default configuration.
Enter the configuration file name. The file name can include a path (default: /home/user/.ossutilconfig. Press Enter to use the default path. If you set it to another path, you need to set the --config-file option to that path when using commands):
-
Set the tool's language as prompted.
Enter the language CH or EN. By default, the interface of ossutil is in the language that is used by the operating system. The configuration takes effect after the config command is successfully run.
-
Set the Endpoint, AccessKey ID, AccessKey Secret, and STSToken parameters as prompted. The stsToken parameter is only required if you access OSS using temporary access credentials provided by the Security Token Service (STS). Otherwise, you can leave this parameter empty.
The following table describes the parameters:
Parameter
Required
Description
endpoint
Yes
Specify the endpoint of the region in which the bucket is located. For example, to use the public endpoint in the China (Hangzhou) region in this example, set it to
https://oss-cn-hangzhou.aliyuncs.com
.If you want to access OSS through other Alibaba Cloud products in the same region, use the internal endpoint and set it to
https://oss-cn-hangzhou-internal.aliyuncs.com
.For more information about endpoints in each region, see OSS regions and endpoints.
accessKeyID
Yes
Specify the AccessKey of the account. For more information about how to obtain the AccessKey, see Create an AccessKey.
accessKeySecret
Yes
stsToken
No
This parameter is required only when you use temporary access credentials to access an OSS bucket. If you do not use temporary access credentials to access an OSS bucket, you can leave this parameter empty. For more information about how to generate an stsToken, see AssumeRole - Obtain temporary identity credentials for role assumption.
-
If you set the configuration file path in Step 2, you must add the -c option to specify the configuration file each time you use a command.
For example, if the configuration file is saved as /home/config, the command format for using ls is as follows:
ossutil -c /home/config ls oss://examplebucket
Command configuration file
You can save common credentials and configurations to the configuration file for easy use. The configuration file is in INI format and consists of sections and keys. The configuration parameters are stored in the specified sections. The following table describes the common configuration parameters:
Configuration parameter | Description | Example code |
language | Specifies the language that ossutil uses. Valid values:
|
|
endpoint | The endpoint of the region in which the bucket is located. |
|
accessKeyID | The AccessKey ID that uniquely identifies a user. |
|
accessKeySecret | The AccessKey secret that authenticates the identity of the user. |
|
stsToken | The security token that is used to authenticate the request. |
|
mode | The mode used for authentication. Valid values: AK, StsToken, RamRoleArn, and EcsRamRole. |
|
ramRoleArn | The ARN of the RAM role in RamRoleArn mode for authentication. |
|
roleSessionName | The name of the session in RamRoleArn mode for authentication. If you do not specify this parameter, a random value is generated. |
|
tokenTimeout | The validity period of the security token. This parameter is used in RamRoleArn mode. Unit: seconds. Default value: 3600. |
|
ecsRoleName | The role name in EcsRamRole mode for authentication. |
|
For more information about command configuration parameters, see Edit configuration file.
Command-line options
In addition to specifying parameters in the configuration file, you can also use command-line options to specify related configurations. Command-line options take precedence over the parameters specified in the configuration file. The following table describes the common command-line options:
Option | Description | Example code |
--loglevel | The log level. By default, this option is left empty, which indicates that no log files are generated. Valid values:
|
|
--connect-timeout | The timeout period for the client to connect to the server. Default value: 120. Unit: seconds. |
|
--read-timeout | The timeout period for the client to read data from the server. Default value: 1200. Unit: seconds. |
|
--retry-times | The number of times an operation is retried if the operation fails. Default value: 10. |
|
-e, --endpoint | The domain name to which the request is sent. |
|
-i, --access-key-id | The Accesskey ID that you want to use to access OSS. |
|
-k, --access-key-secret | The Accesskey secret that you want to use to access OSS. |
|
-t, --sts-token | The security token that you want to use to access OSS. |
|
--mode | The mode used for authentication. Valid values: AK, StsToken, RamRoleArn, and EcsRamRole. By default, this parameter is left empty. | The following code provides an example on how to access OSS in AK mode:
|
--ram-role-arn | The ARN of the RAM role in RamRoleArn mode for authentication. |
|
--role-session-name | The name of the session in authentication mode. |
|
--token-timeout | The validity period of the security token. Unit: seconds. Default value: 3600. |
|
--ecs-role-name | The role name in EcsRamRole mode for authentication. |
|
For more information about option configuration, see Common options.
Configure access credentials
You can configure access credentials by specifying parameters in configuration files or command-line options.
Use AccessKey pairs to access data
In this example, a bucket named example-bucket in the China (Hangzhou) region is used.
-
Specify the parameters in the configuration file
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com accessKeyID = LTAI4Fw2NbDUCV8zYUzA**** accessKeySecret = 67DLVBkH7EamOjy2W5RVAHUY9H****
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket
-
Specify the command-line options
You can also specify command-line options to import the AccessKey pair. The following code provides an example:
ossutil64 -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H**** ls oss://example-bucket
ImportantIf you specify command-line options to import the AccessKey pair, the AccessKey pair may be recorded by the log system and is highly prone to leaks. Proceed with caution.
Use the temporary access credentials obtained from STS to access data
In this example, a bucket named example-bucket in the China (Hangzhou) region is used.
-
Specify the parameters in the configuration file
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com accessKeyID = STS.LTAI4Fw2NbDUCV8zYUzA**** accessKeySecret = 67DLVBkH7EamOjy2W5RVAHUY9H**** stsToken = yourSecurityToken
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket
-
Specify the command-line options
You can also specify command-line options to import the temporary access credentials. The following code provides an example:
ossutil64 -e oss-cn-hangzhou.aliyuncs.com -i STS.LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H**** -t yourSecurityToken ls oss://example-bucket
NoteIf you specify command-line options to import the temporary access credentials, they may be recorded by the log system and are highly prone to leaks. Proceed with caution.
Use a RAM role
In this example, a bucket named example-bucket in the China (Hangzhou) region and a RAM role named ramRoleArnExample are used.
-
Specify the parameters in the configuration file
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com accessKeyID = LTAI4Fw2NbDUCV8zYUzA**** accessKeySecret = 67DLVBkH7EamOjy2W5RVAHUY9H**** mode = RamRoleArn ramRoleArn = acs:ram::137918634953****:role/Alice roleSessionName = session_name_example (This parameter is optional.) tokenTimeout = 1800 (This parameter is optional.)
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket
-
Specify the command-line options
You can specify command-line options to import the AccessKey pair as well. Below is an example:
ossutil64 -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H**** --mode RamRoleArn --ram-role-arn acs:ram::137918634953****:role/Alice ls oss://example-bucket
NoteIf you specify command-line options to import an AccessKey pair, be aware that the AccessKey pair may be logged by the system. AccessKey pairs are highly susceptible to leakage, so proceed with caution.
Use instance RAM roles
You can attach a RAM role to an ECS instance, which allows you to access ossutil using temporary access credentials obtained from STS. These credentials are automatically generated and updated, and applications can retrieve them using the instance metadata URL. The RAM role enhances the security of your AccessKey pair and facilitates fine-grained permission control and management.
Create an instance RAM role on the ECS instance before using it. For more information, see Create an instance RAM role.
In this example, a bucket named example-bucket in the China (Hangzhou) region and a RAM role named EcsRamRoleOss attached to an ECS instance are used.
-
Specify the parameters in the configuration file
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com mode = EcsRamRole ecsRoleName = EcsRamRoleOss
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket
-
Specify the command-line options
You can also specify command-line options to import the instance RAM role. The following code provides an example:
ossutil64 -e oss-cn-hangzhou.aliyuncs.com --mode EcsRamRole --ecs-role-name EcsRamRoleOss ls oss://example-bucket
Specify endpoints for the buckets
When managing multiple buckets with ossutil, you must specify an endpoint for each bucket. You can use one of the following methods:
-
Specify the parameters in the configuration file
In the configuration file, add a [Bucket-Endpoint] section to specify an endpoint for each bucket in the following format:
[Bucket-Endpoint] bucket1 = endpoint1 bucket2 = endpoint2 ...
In this example, the following buckets are used: example-bucket-hz in the China (Hangzhou) region, example-bucket-bj in the China (Beijing) region, and example-bucket-sh in the China (Shanghai) region.
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com accessKeyID = LTAI4Fw2NbDUCV8zYUzA**** accessKeySecret = LTAI4Fw2NbDUCV8zYUzA**** [Bucket-Endpoint] example-bucket-hz=oss-cn-hangzhou.aliyuncs.com example-bucket-bj=oss-cn-beijing.aliyuncs.com example-bucket-sh=oss-cn-shanghai.aliyuncs.com
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket-hz ossutil64 -c ~/.myossutilconfig ls oss://example-bucket-bj ossutil64 -c ~/.myossutilconfig ls oss://example-bucket-sh
-
Specify the command-line options
In this example, the following buckets are used: example-bucket-hz in the China (Hangzhou) region, example-bucket-bj in the China (Beijing) region, and example-bucket-sh in the China (Shanghai) region.
Specify the account information in ~/.myossutilconfig.
[Credentials] endpoint = oss-cn-hangzhou.aliyuncs.com accessKeyID = LTAI4Fw2NbDUCV8zYUzA**** accessKeySecret = 67DLVBkH7EamOjy2W5RVAHUY9H****
Specify the endpoint using the -e parameter.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket-hz ossutil64 -c ~/.myossutilconfig -e oss-cn-beijing.aliyuncs.com ls oss://example-bucket-bj ossutil64 -c ~/.myossutilconfig -e oss-cn-shanghai.aliyuncs.com ls oss://example-bucket-sh
Configure custom Domain Names
ossutil allows you to access OSS resources using a custom domain name. Before doing so, you must configure the mapping between a bucket and a custom domain name in the configuration file.
Add a [Bucket-Cname]
section in the configuration file to specify a custom domain name for each bucket in the following format:
[Bucket-Cname]
bucket1 = cname1
bucket2 = cname2
...
In this example, a bucket named example-bucket in the China (Hangzhou) region and the custom domain name cname.example-***.com are used.
Generate the following configuration file and save it to ~/.myossutilconfig.
[Credentials]
accessKeyID = LTAI4Fw2NbDUCV8zYUzA****
accessKeySecret = 67DLVBkH7EamOjy2W5RVAHUY9H****
[Bucket-Cname]
example-bucket=cname.example-***.com
Run the following command to query the objects in the bucket.
ossutil64 -c ~/.myossutilconfig ls oss://example-bucket