Linux で gpg を使用してファイルを保護する方法

共有 Linux マシンまたは環境で作業する場合、機密情報を含むファイルを非表示にしたり保護したりする必要がある場合があります。幸いなことに、ほとんどの Linux ディストリビューションに既にプリインストールされている GnuPG というツールがあり、このツールを便利に利用できます。この投稿では、非常に基本的なシナリオでこのツールをいかに簡単かつ迅速に使用できるかについて説明します。

Encrypt and decrypt a file with passphrase

# encrypt and enter a strong passphrase
$ gpg -c filename

# decrypt without entering passphrase as it's cached
$ gpg -d filename.gpg

Optional optimal options

# disable passphrase cache so that decryption requires passphrase
$ gpg -c --no-symkey-cache filename
$ gpg -d --no-symkey-cache filename
# another option is add a line no-symkey-cache to ~/.gnupg/gpg.conf
# so that there is no need to provide command line option every time:
# ~$ cat .gnupg/gpg.conf
# no-symkey-cache

# delete original unencrypted file and
# remove .gpg extension of the encrypted one
$ rm filename
$ mv filename.gpg filename

# change to hidden file
$ mv filename .filename

参考文献

linux security