LoginSignup
11
10

More than 5 years have passed since last update.

s3cmdでファイルを暗号化して保存する

Last updated at Posted at 2013-08-30

s3cmdを使ってEC2からS3にDBバックアップという素晴らしい記事を見ながらs3cmdの設定している時に、「Encryption password」という項目があったのが気になったので確認してみた。


まず、パスワードあり版の設定をする。

$ s3cmd -c ./.s3cfg-encryption --configure

これで./.s3cfg-encryptionというファイルが出来て、途中で入力した「Encryption password」が書かれているのだけど、これだけでは暗号化する設定になっていないので、ファイルを開いて、

encrypt = False

となっている所を

encrypt = True

に書き換えておく。


次に、パスワード無し版の設定をする。

$ s3cmd -c ./.s3cfg-no-encryption --configure

今回暗号化するファイルを準備する。

$ echo 'This is a secret file' > secret.txt

で、確認。

パスワードあり設定を使ってファイルをS3に置く。

$ s3cmd -c ./.s3cfg-encryption put ./secret.txt $BUCKET

パスワード無し設定を使ってダウンロードする。

$ s3cmd -c ./.s3cfg-no-encryption get $BUCKET/secret.txt ./downloaded-encrypted.txt
$ cat ./downloaded-encrypted.txt
(暗号化されている)

パスワードあり設定を使ってダウンロードする。

$ s3cmd -c ./.s3cfg-encryption get $BUCKET/secret.txt ./downloaded-decrypted.txt
$ cat ./downloaded-decrypted.txt
This is a secret file

というわけで、パスワードを平文で保存しているようなデータベースのバックアップでも、ある程度安心してかつ簡単にS3を使えますね。


あと、パスワードが分かっていればgpgコマンドで直接復号することもできます、勿論。

$ gpg -d ./downloaded-encrypted.txt
(パスワード入力)
This is a secret file
11
10
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10