Encrypting a Directory using TrueCrypt

Create a password protected encrypted file container using TrueCrypt stored in the path ~/encrypted/encrypted.tc. The following script will decrypt this file and mount it as the directory ~/encrypted/encrypted. It will also unmount the directory when you are done.
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# truecrypt-encrypted
# Mount and unmount an encrypted TrueCrypt directory.
# 
# Author: Dave Lehman <dave@nowherelan.com>; http://nowherelan.com
# Date Created: 2012-01-01
# Version: 1.0
################################################################################
 
SCRIPTNAME=truecrypt-encrypted
ENCRYPTED_FILE=$HOME/encrypted/encrypted.tc
DECRYPTED_MNT=$HOME/encrypted/encrypted
 
 
mount(){
    mkdir -p $DECRYPTED_MNT
    truecrypt --text $ENCRYPTED_FILE $DECRYPTED_MNT
    return 0
}
 
umount(){
    truecrypt --text --dismount $DECRYPTED_FILE
    return 0
}
 
status(){
    truecrypt --text --list $DECRYPTED_FILE
    return 0
}
 
case "$1" in
    --mount)
        mount
        ;;
    --umount)
        umount
        ;;
    --status)
        status
        ;;
    *)
        echo "Usage: $SCRIPTNAME {--mount|--umount|--status}" >&2
        exit 0
        ;;
esac
 
exit 0

Leave a Reply

Your email address will not be published. Required fields are marked *

*