Blog / Linux/ Installing and Configuring Baidu Cloud BOS CLI Tool on CentOS

Installing and Configuring Baidu Cloud BOS CLI Tool on CentOS

在 CentOS 系统上安装与配置百度云 BOS CLI 工具

Environment Preparation: Installing Python and pip

The BOS CLI tool is developed in Python, so you must first install Python and the pip package manager.

sudo yum install python python-devel python-setuptools python-pip

Note: In newer CentOS versions, the python-pip package may have changed. If the above command fails, try sudo yum install python2-pip or install via curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py.

Installing the BOS CLI Tool

Download and Extract

Download the CLI tool package for your system from the official Baidu Cloud SDK page. Note that the version in the original link (0.10.8) is very old; visit the official documentation for the latest version.

# Example command (replace with the latest link)
wget https://sdk.bce.baidu.com/console-sdk/bce-cli-latest-linux-x86-64.zip
unzip bce-cli-latest-linux-x86-64.zip

Install and Configure Environment Variables

Navigate to the extracted directory and run the installation.

cd bce-cli-*
sudo python setup.py install

After installation, add the CLI tool's executable directory to your system's PATH environment variable to call the bce command from anywhere.

# Assuming the extraction directory is /home/user/bce-cli-x.y.z
# Temporary addition (valid only for the current terminal session)
export PATH=/home/user/bce-cli-x.y.z:$PATH
# Permanent addition: add the following line to the end of ~/.bashrc or ~/.bash_profile
echo 'export PATH=/home/user/bce-cli-x.y.z:$PATH' >> ~/.bashrc
source ~/.bashrc

Important: When modifying PATH, incorrect operations (e.g., export PATH=/some/path without including system paths) can cause basic commands like ls to fail. If this happens, restore the default PATH with:

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Configuring the BOS CLI

Before first use, configure your authentication and default parameters via the interactive command.

bce -c

When prompted, enter:

  • BOS Access Key ID: Your Access Key from the "Security Authentication" section of the Baidu Cloud console.
  • BOS Secret Access Key: The corresponding Secret Key.
  • Default region name: The region of your BOS Bucket, e.g., bj (Beijing), gz (Guangzhou), su (Suzhou).
  • Default domain: Typically use the default <region>.bcebos.com.
  • For other options like "Auto-switch domain," "Resume upload validity period," "HTTPS protocol," and "Parallel upload threads," press Enter to accept the recommended defaults.

Configuration is saved in ~/.bce/config.

Using the CLI for Batch File Uploads

After configuration, use the bce bos cp command to upload files or directories.

# Recursively upload all files from the local ./temp/ directory to a bucket named bce-test
bce bos cp ./temp/ bos:/bce-test -r

Command breakdown:

  • cp: Copy/upload command.
  • ./temp/: Local source directory path.
  • bos:/bce-test: Target BOS Bucket in the format bos:<bucket-name>.
  • -r: Recursively upload all files and subdirectories.

Use bce bos --help or bce bos cp --help for more detailed parameter information, such as setting storage types or upload speed limits.

Post a Comment

Your email will not be published. Required fields are marked with *.