Just Start Typing Text and Press Enter

Menu
Close
Nov 24, 2026

How To Pull Files From An AWS S3 Bucket With s3cmd On Linux & Mac (2026 Update)

0 Comment | By
Illustration of a cloud storage bucket sending file icons to a laptop

This is the updated version of my 2019 post, How to pull / get files from an AWS bucket using the S3 command (s3cmd) on Linux & Mac. The original is still up. The core command is the same, but install and credential advice has changed, and now we cover whole folders and syncing too.

What you need

  • An Amazon S3 bucket with at least one file in it.
  • AWS credentials that are allowed to read that bucket.
  • A terminal on Linux or Mac.

Install s3cmd

The latest release is 2.4.0, from December 2023 (PyPI). Pick the option that fits your machine.

On a Mac, use Homebrew:

brew install s3cmd

On Fedora, s3cmd is in the main repositories (Fedora packages):

sudo dnf install s3cmd

On RHEL and its relatives, s3cmd comes from EPEL, which is a separate repository. The same dnf command only works after EPEL is enabled. Install the epel-release package for your version first; Red Hat’s note covers RHEL itself, including what to do if the package isn’t found (Red Hat on EPEL).

On Debian, the package is available too. Debian stable currently lists 2.4.0 (Debian tracker). Other Debian-based distros may carry an older version, so check yours with s3cmd –version after installing.

sudo apt install s3cmd

If you want it from PyPI, don’t use a plain global pip install. Many current Linux distros mark their system Python as externally managed, which tells pip not to change it (Python packaging spec). Use a virtual environment:

python3 -m venv ~/s3cmd-env
source ~/s3cmd-env/bin/activate
pip install s3cmd
s3cmd --version

The activate step is what makes the plain s3cmd command work, and it only lasts for that terminal window. In a new window, run the source line again. Or skip activating and call ~/s3cmd-env/bin/s3cmd by its full path every time.

Or use pipx, which sets up an isolated environment for you and puts the command on your PATH (Python packaging guide):

pipx install s3cmd

Pick your credentials carefully

AWS recommends temporary credentials over long-term access keys wherever you can use them, and says people should get them through federation, such as IAM Identity Center (IAM best practices). The same page lists third-party AWS clients as a case where long-term IAM user keys are still used. s3cmd is a third-party client, so long-term keys are one option for this workflow. s3cmd can also take temporary credentials with a session token (its –access_token option, listed on the usage page). If your account is set up with Identity Center, the AWS CLI section near the end is the better fit.

If you do use keys with s3cmd, keep their permissions as small as the job. For downloading from one bucket, that means listing the bucket and reading its objects, and nothing else:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
      "Resource": "arn:aws:s3:::my-test-bucket-20"
    },
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "arn:aws:s3:::my-test-bucket-20/*"
    }
  ]
}

Swap in your own bucket name. Read-only is not harmless. Anyone who gets those keys can download everything the policy allows and run up transfer charges on your account. Don’t put them in a repo or a shared folder, and delete or replace them when you no longer need them. AWS also suggests using the last-used information on keys to find ones that are no longer needed.

Set up s3cmd

Run the setup once. Adding the bucket name makes the connection test check that bucket instead of trying to list every bucket you own, so the test only needs access to that one bucket (s3cmd usage):

s3cmd --configure s3://my-test-bucket-20
  1. Paste the access key and secret key when asked.
  2. For Default Region, enter the region your bucket is in. You can see it in the S3 console. s3cmd itself defaults to US if you leave it alone.
  3. Keep “Use HTTPS protocol” on Yes. That is s3cmd’s default, and AWS recommends encrypted connections for S3 (S3 security best practices, linked at the end).
  4. Leave the encryption password and GPG path alone unless you use s3cmd’s own file encryption.
  5. Say yes to the connection test.

Your settings are saved to ~/.s3cfg, a plain text file. Treat it like a password file.

See what is in the bucket

s3cmd ls s3://my-test-bucket-20

Pull down one file

Same as the original post. Go to the folder where you want the file, then run:

s3cmd get s3://my-test-bucket-20/jimmy_wichard.jpg

You can also name the destination yourself:

s3cmd get s3://my-test-bucket-20/jimmy_wichard.jpg ~/Desktop/jimmy.jpg

If a file with that name already exists, s3cmd stops with an error telling you to use –force, –continue or –skip-existing, or to give the file a new name. Add –force only when you do want to replace it.

Pull down a whole folder

In the original I said I would cover more than one file at a time. Here it is. Use –recursive:

s3cmd get --recursive s3://my-test-bucket-20/images/ ./images/

Add –dry-run first if you want to see what would be downloaded without downloading anything.

Keep a local folder in sync

If you pull from the same place regularly, sync only brings down what is new or changed. By default it compares size and MD5 checksum (s3cmd man page):

s3cmd sync --dry-run s3://my-test-bucket-20/images/ ./images/

Look over the dry run, then run the same command without –dry-run. Add –skip-existing to skip any file you already have locally. Don’t add –delete-removed unless you want local files deleted when they are no longer in the bucket.

To leave files out, use –exclude and –include. This skips temp files:

s3cmd sync --exclude '*.tmp' s3://my-test-bucket-20/images/ ./images/

If a download stops partway

For a single file, –continue picks a partial download back up:

s3cmd get --continue s3://my-test-bucket-20/big-backup.tar.gz

For a folder, run the sync again. Files that already match are skipped. Also know that s3cmd keeps going after a failed file and exits with status 2 at the end. Add –stop-on-error if you want it to stop at the first failure (s3cmd README).

Watch the costs

Downloads can cost money. AWS charges for S3 requests and for data transferred out to the internet. A recursive get or sync makes at least one request per file, so a bucket with many files adds up. Check the current rates on the S3 pricing page for your region before pulling a large bucket.

The AWS CLI alternative

AWS has its own command line tool. If you sign in through IAM Identity Center, it can get temporary credentials for you with aws configure sso (AWS CLI SSO setup), so no long-term keys sit on your machine. The same jobs look like this (aws s3 cp, aws s3 sync):

aws s3 cp s3://my-test-bucket-20/jimmy_wichard.jpg .
aws s3 sync s3://my-test-bucket-20/images/ ./images/

Wrap up

You can now pull one file or a whole folder, keep a local copy in sync, and test a job with a dry run first. Thanks for reading.

Sources

Leave A Comment

DON'T MISS ANY UPDATES