Just Start Typing Text and Press Enter

Menu
Close
Nov 25, 2026

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

0 Comment | By
Illustration of file, folder and photo icons flying from a laptop up into a cloud storage bucket

This is the updated version of my 2019 post, How to push / put files to an AWS bucket using the S3 command (s3cmd) on Linux & Mac. The original is still up. The core command is the same, but there is a fix for the Mac path, safer credential advice, and now we cover whole folders, syncing and dry runs.

What you need

  • An Amazon S3 bucket you can write to.
  • AWS credentials that are allowed to upload to that bucket.
  • A terminal on Linux or Mac, and a little comfort with the command line.

This post is the other half of my 2026 pull post. Install and first-time setup are the same, so here is the short version.

Install s3cmd

The latest release is 2.4.0, from December 2023. On a Mac, use Homebrew:

brew install s3cmd

On Debian, Ubuntu and relatives:

sudo apt install s3cmd

If you want it from PyPI, use a virtual environment rather than a global pip install. Many current Linux distros mark their system Python as externally managed.

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

Check your version with s3cmd –version, since some distros carry an older one. Fedora, RHEL and pipx steps are in the pull post.

Give the keys upload rights and nothing else

AWS recommends temporary credentials over long-term access keys wherever you can use them. s3cmd is a third-party client, so long-term keys are still a common choice here. If you use keys, keep the permissions as small as the job. For uploading to one bucket, that is listing the bucket and writing objects:

Illustration of a key and padlock shield beside a bucket with a single arrow pointing in
Illustration: keys that can only upload.
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
      "Resource": "arn:aws:s3:::my-test-bucket-20"
    },
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject"],
      "Resource": "arn:aws:s3:::my-test-bucket-20/*"
    }
  ]
}

Swap in your own bucket name. Two notes. If you later use sync with –delete-removed, the keys also need s3:DeleteObject. And write-only is not harmless: anyone with these keys can fill your bucket and run up charges. Keep them out of repos and shared folders.

Then run the one-time setup. Adding the bucket name makes the connection test check that bucket instead of listing every bucket you own:

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

Paste the keys, enter the region your bucket is in, keep HTTPS on, and say yes to the test. Your settings are saved to ~/.s3cfg, a plain text file. Treat it like a password file.

Push one file

First, go to the folder that holds your file. In the original post I used a Mac path that was wrong (/home is a Linux path). On both Linux and Mac, your Desktop is:

cd ~/Desktop

Now send the file. The format is s3cmd put, the local file, then the bucket and the name to give it there:

s3cmd put jimmy_wichard.jpg s3://my-test-bucket-20/jimmy_wichard.jpg
Illustration of a laptop terminal sending one file to a cloud bucket
Illustration: one put command, one file.

Check that it arrived:

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

Same name means overwrite. If an object with that name already exists in the bucket, a put replaces it. If you want a safety net, turn on versioning for the bucket in the S3 console first.

Push several files or choose the name

Give put more than one file, then a destination folder (a prefix) ending in a slash:

s3cmd put photo1.jpg photo2.jpg s3://my-test-bucket-20/images/

To store a file under a different name, spell out the full destination:

s3cmd put jimmy_wichard.jpg s3://my-test-bucket-20/people/jimmy.jpg

Push a whole folder

In the original I said I would cover more than one file. Use –recursive. Add –dry-run first, which shows what would be uploaded without uploading anything:

Illustration of a folder of files being sent to a bucket with a sync symbol between them
Illustration: a whole folder going up, kept in sync.
s3cmd put --recursive --dry-run ./images/ s3://my-test-bucket-20/images/

If the list looks right, run it again without –dry-run. The dry run lists where each file would land, so it is worth the few seconds.

Keep a folder in sync

If you push the same folder regularly, sync only sends what is new or changed. By default it compares size and MD5 checksum:

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

Look over the dry run, then run the same command without –dry-run. To leave files out, use –exclude. This skips temp files:

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

Careful with –delete-removed. Adding –delete-removed deletes objects in the bucket that no longer exist in your local folder. Only use it when you want the bucket to mirror the folder, and run it with –dry-run first.

A few useful extras

  • Lower storage cost: –storage-class=STANDARD_IA (the current man page also lists ONEZONE_IA, INTELLIGENT_TIERING, GLACIER and DEEP_ARCHIVE). Check the S3 pricing page for how each class bills before you use one.
  • Server-side encryption: –server-side-encryption.
  • Big files: files larger than the chunk size (15 MB by default) upload in parts. Change it with –multipart-chunk-size-mb. If an upload stops partway, –continue-put can pick it back up, though the man page says to use it at your own risk.
  • Cap the speed: –limit-rate=1m keeps an upload from using all your bandwidth.

Public files and ACLs. The old advice for sharing a file was –acl-public. AWS now creates new buckets with ACLs disabled, and requests to set an ACL fail in that case. For a private bucket, ignore ACL options. To share files, use a bucket policy or a time-limited link instead.

If you see the python-magic warning

The original post showed this warning:

WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.

It is harmless. It only means s3cmd guesses each file’s type from its extension. To remove it, install the python-magic package into the same Python that runs s3cmd. On a Mac, install the libmagic library first:

brew install libmagic
pip install python-magic

The old sudo apt-get install python-magic line from 2019 is for Python 2 and no longer applies.

Watch the costs

Uploads are billed per request, and storage is billed per GB each month. A recursive put or sync makes at least one request per file, so a folder with many small files adds up. Check current rates on the S3 pricing page for your region before pushing a large folder.

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, so no long-term keys sit on your machine. The same jobs look like this:

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

Wrap up

You can now push one file, several files or a whole folder, keep a folder in sync, and test any job with a dry run first. Thanks for reading.

Sources

Leave A Comment

DON'T MISS ANY UPDATES