{"id":7130,"date":"2021-06-12T13:01:47","date_gmt":"2021-06-12T13:01:47","guid":{"rendered":"https:\/\/linuxways.net\/?p=7130"},"modified":"2021-06-12T13:01:47","modified_gmt":"2021-06-12T13:01:47","slug":"how-to-install-s3cmd-in-linux-and-manage-amazon-s3-buckets","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-install-s3cmd-in-linux-and-manage-amazon-s3-buckets\/","title":{"rendered":"How to Install s3cmd in Linux and Manage Amazon s3 Buckets"},"content":{"rendered":"<p><strong>S3 , <\/strong>&#8211; Simple Storage Service- is Amazon\u2019s storage service that provides IT teams with a secure, scalable, and reliable way to store and retrieve files and folders on the cloud. S3 helps you make the most out of your data by making sure that it is available when needed and scalable as demand grows.<\/p>\n<p>Conventionally, S3 is accessed from a web browser after signing in to your AWS account. This can also be achieved on command-line using a nifty tool called s3cmd. The <strong>s3cmd<\/strong> utility is an opensource command-line tool that allows you to access and manage your S3 service. It allows you to create\/delete buckets, add\/remote files and folders and list the contents of your S3 buckets.<\/p>\n<p>This guide will seek to help you install s3cmd on Linux and help you make the most of it to manage your S3 account.<\/p>\n<h2><strong>How to install s3cmd on Linux<\/strong><\/h2>\n<p>Installing s3cmd on major Linux distributions such as Ubuntu, CentOS &amp; RHEL is quite a walk in the park. This is because the s3cmd package is available on their repositories.<\/p>\n<p>Let\u2019s check out how you can install s3cmd on various distributions:<\/p>\n<h3><strong>On Ubuntu \/ Debian flavors<\/strong><\/h3>\n<p>For Debian \/ Ubuntu distributions use the APT package manage as follows:<\/p>\n<pre><strong>$ sudo apt install s3cmd<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"370\" class=\"wp-image-7131\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-359.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-359.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-359-300x151.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/strong><\/p>\n<h3><strong>On CentOS 8 \/ RHEL 8<\/strong><\/h3>\n<p>On CentOS \/ RHEL distros install s3cmd using the command below:<\/p>\n<pre><strong>$ sudo dnf install s3cmd<\/strong><\/pre>\n<h3><strong>On SUSE Linux <\/strong><\/h3>\n<p>For SUSE Enterprise server , start by adding the repository and using the <strong>zypper <\/strong>command-line tool as shown.<\/p>\n<pre><strong>$ sudo zypper addrepo http:\/\/s3tools.org\/repo\/SLE_11\/s3tools.repo<\/strong><\/pre>\n<pre><strong>$ zypper install s3cmd<\/strong><\/pre>\n<h2><strong>Installation from source<\/strong><\/h2>\n<p>If your Linux distribution is not listed above, don\u2019t fret. You can install from source which will work in all distributions.<\/p>\n<p>First, download the zip file of the latest s3cmd version, which by this time is s3cmd 2.1.0.<\/p>\n<pre><strong>$ wget https:\/\/sourceforge.net\/projects\/s3tools\/files\/s3cmd\/2.1.0\/s3cmd-2.1.0.zip<\/strong><\/pre>\n<p>In your home directory, you should see the <strong>s3cmd-2.1.0.zip <\/strong>zip file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"888\" height=\"179\" class=\"wp-image-7132\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-360.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-360.png 888w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-360-300x60.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-360-768x155.png 768w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/p>\n<p>Next, unzip the file.<\/p>\n<pre><strong>$ unzip s3cmd-2.1.0<\/strong><\/pre>\n<p>Navigate to the uncompressed folder<\/p>\n<pre><strong>$ cd s3cmd-2.1.0<\/strong><\/pre>\n<p>And execute the command shown to install from source.<\/p>\n<pre><strong>$ sudo python3 setup.py install<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"353\" class=\"wp-image-7133\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-361.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-361.png 887w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-361-300x119.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-361-768x306.png 768w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><\/strong><\/p>\n<h2><strong>Setting up the s3cmd environment<\/strong><\/h2>\n<p>Before we begin interacting with Amazon S3, we need to set up the s3cmd tool by providing the necessary credentials such as Access Key &amp; Secret access to our account. So, run the command below to configure the s3cmd environment.<\/p>\n<pre><strong>$ s3cmd --configure<\/strong><\/pre>\n<p>Provide the access key, secret access , region and encryption password as shown in the screenshot below.<\/p>\n<p>Be sure to use the HTTPS protocol for enhanced security.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"582\" class=\"wp-image-7134\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-362.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-362.png 890w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-362-300x196.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-362-768x502.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"589\" class=\"wp-image-7135\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-363.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-363.png 890w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-363-300x199.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-363-768x508.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/p>\n<h2><strong>List s3 buckets<\/strong><\/h2>\n<p>We have successfully configured the s3cmd tool, and we can now begin interacting with Amazon S3. Before you start interacting with S3, ensure that the user on your AWS has been configured with Amazon S3 IAM role.<\/p>\n<p>To list the existing S3 buckets on your account, execute the command:<\/p>\n<pre><strong>$ s3cmd ls<\/strong><\/pre>\n<p>So far, we have none since we are just getting started out.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"157\" class=\"wp-image-7136\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-364.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-364.png 889w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-364-300x53.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-364-768x136.png 768w\" sizes=\"auto, (max-width: 889px) 100vw, 889px\" \/><\/p>\n<p>Let\u2019s create one \ud83d\ude42<\/p>\n<h2><strong>Create an S3 bucket<\/strong><\/h2>\n<p>To create a new S3 bucket, run the command shown. The command below creates a bucket in S3 called <strong>linuxways.<\/strong><\/p>\n<pre><strong>$ s3cmd mb s3:\/\/linuxways<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"168\" class=\"wp-image-7137\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-365.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-365.png 890w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-365-300x57.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-365-768x145.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/p>\n<p>You can head over to your AWS account and confirm that the bucket has been created as shown.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1111\" height=\"413\" class=\"wp-image-7138\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-366.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-366.png 1111w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-366-300x112.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-366-1024x381.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-366-768x285.png 768w\" sizes=\"auto, (max-width: 1111px) 100vw, 1111px\" \/><\/p>\n<h2><strong>Upload a file to S3 bucket<\/strong><\/h2>\n<p>To upload a regular file to your bucket, invoke the <strong>put <\/strong>option followed by the file and the path to S3 bucket. The command below uploads the file <strong>hello.sh <\/strong>to S3.<\/p>\n<pre><strong>$ s3cmd put hello.sh s3:\/\/linuxways\/<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"212\" class=\"wp-image-7139\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-367.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-367.png 890w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-367-300x71.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-367-768x183.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/p>\n<h2><strong>Upload a directory to S3 bucket<\/strong><\/h2>\n<p>To upload a directory, use the <strong>-r<\/strong> flag for adding the directory recursively alongside its contents. Take care not to add the leading \/ as this will only add the directory\u2019s contents and not the directory itself.<\/p>\n<p>Here, we are uploading the <strong>Pictures <\/strong>directory that contains a JPG image file.<\/p>\n<pre><strong>$ s3cmd put -r Pictures s3:\/\/linuxways\/<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"888\" height=\"231\" class=\"wp-image-7140\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-368.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-368.png 888w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-368-300x78.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-368-768x200.png 768w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/p>\n<h2><strong>List contents of S3 bucket<\/strong><\/h2>\n<p>To view or display what your S3 bucket contains, run the command.<\/p>\n<pre><strong>$ s3cmd ls s3:\/\/linuxways\/<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"884\" height=\"176\" class=\"wp-image-7141\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-369.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-369.png 884w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-369-300x60.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-369-768x153.png 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/p>\n<h2><strong>Delete a file or directory from an S3 bucket<\/strong><\/h2>\n<p>If you wish to remove or delete a file you no longer need, use the <strong>del <\/strong>option as shown.<\/p>\n<pre><strong>$ s3cmd del s3:\/\/linuxways\/hello.sh<\/strong><\/pre>\n<p>To delete a directory, use the same syntax as follows. However, this only works if the directory is empty.<\/p>\n<pre><strong>$ s3cmd del s3:\/\/linuxways\/Pictures<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"884\" height=\"255\" class=\"wp-image-7142\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-370.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-370.png 884w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-370-300x87.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-370-768x222.png 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/p>\n<p>If a directory is not empty, use the <strong>-r <\/strong>option to recursively delete all its contents as shown.<\/p>\n<pre><strong>$ s3cmd del -r s3:\/\/linuxways\/Pictures\/<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"749\" height=\"125\" class=\"wp-image-7143\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-371.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-371.png 749w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-371-300x50.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/p>\n<h2><strong>Remove a bucket from S3<\/strong><\/h2>\n<p>If you no longer require your bucket, you can delete it as follows.<\/p>\n<pre><strong>$ s3cmd rb s3:\/\/linuxways<\/strong><\/pre>\n<p>If the bucket still contains some files and folders, you will run into the error below informing you that the bucket is not empty.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"885\" height=\"179\" class=\"wp-image-7144\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-372.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-372.png 885w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-372-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-372-768x155.png 768w\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" \/><\/p>\n<p>The solution is to go back and delete all the files and directories in your bucket and try again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"884\" height=\"163\" class=\"wp-image-7145\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-373.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-373.png 884w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-373-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-373-768x142.png 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/p>\n<h2><strong>Wrapping up<\/strong><\/h2>\n<p>That was a summary of the s3cmd command-line tool and how you can use it to manage your Amazon S3 storage feature.<\/p>","protected":false},"excerpt":{"rendered":"<p>S3 , &#8211; Simple Storage Service- is Amazon\u2019s storage service that provides IT teams with a secure, scalable, and reliable way to store and retrieve files and folders&hellip;<\/p>","protected":false},"author":1,"featured_media":7238,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,165,2],"tags":[366,93,17,198,365,100],"class_list":["post-7130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-red-hat","category-ubuntu","tag-amazon-s3-buckets","tag-centos-8","tag-debian-10","tag-red-hat-enterprise-linux-8","tag-s3cmd","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=7130"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7130\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/7238"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=7130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=7130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=7130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}