Last active
May 8, 2017 17:11
-
-
Save AGhost-7/0b3c51c6c0f4e3e4d41a to your computer and use it in GitHub Desktop.
Encrypt Vagrant VMs on a separate partition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Encrypting Vagrant VMs: I don't want to encrypt my entire filesystem due to | |
| # the performance hog that it is. I don't even want it to decrypt | |
| # automatically on login; I only really need the encryption for certain | |
| # projects that I'm working on. | |
| # | |
| # One of the issues with this solution is that it globally changes where | |
| # VirtualBox and Vagrant will save their data. I wasn't able to find a way | |
| # to make VirtualBox load a VM from a different location aside from changing | |
| # things globally. | |
| # | |
| # To do this, you need to change where VirtualBox stores the VMs from the GUI, | |
| # in "Preferences Menu > General > Default Machine Folder" | |
| # and now the ~/.bashrc shenanigans. | |
| # This will tell vagrant where to fetch the configuration files to run the VMs. | |
| # They will all be encrypted. | |
| export VAGRANT_HOME=/media/storage/Private/.vagrant.d | |
| # I have a partition which is automatically mounted on login. This is used to | |
| # store large files such as VMs. | |
| decrypt-private-store() { | |
| folder=/media/storage/Private | |
| sudo mount -t ecryptfs $folder $folder \ | |
| -o ecryptfs_cipher=aes \ | |
| -o ecryptfs_key_bytes=16 \ | |
| -o ecryptfs_passthrough=n \ | |
| -o ecryptfs_enable_filename_crypto=n | |
| } | |
| # wrapper for the vagrant command... untested, I think it will work. | |
| # vagrant() { | |
| # # Trick here is to place a file in the private folder when it is decrypted | |
| # # with whatever value you want. If it is encrypted then the text will be | |
| # # all garbled. This checks if the private folder is encrypted, and if so | |
| # # it will run the mount command automatically. | |
| # if [[ `cat $folder/.mounted` != "yes" ]]; then | |
| # decrypt-private-store | |
| # fi | |
| # /usr/bin/vagrant "$@" | |
| # } | |
| # Additional notes: | |
| # If you do this, you'll need to make sure that your mounted filesystem is | |
| # encrypted once you're done. Smart way of doing that would be to have it | |
| # run `sudo umount /media/storage/Private` on logout. | |
| # Sources: | |
| # http://manpages.ubuntu.com/manpages//oneiric/man7/ecryptfs.7.html | |
| # https://opensourcehacker.com/2011/04/15/encrypted-folders-on-ubuntu-linux-using-ecryptfs-on-an-external-hard-drive/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment