Linux Tutorial: How to create a password-protected folder

Ubuntu does not, by default, provide a way to create password-protected directories.  A right-click on a folder does offer to encrypt, but that is done with gpg, which uses a gpg key.  You’d need to email your public key to anyone you wanted to have access to the folder, which is a rather cumbersome procedure when all you want is a simple password protection!

Using the -c flag with gpg (gpg -c) uses symmetrical encryption -  this means a protected file can be opened with a password.  But gpg -c works only on files, not directories.

Truecrypt is an encryption package that does allow the user to create password-protected directories.  Unfortunately, you can’t install truecrypt with apt-get or Synaptic – it is not in any of the repsitories.  But you can get it in .deb form, from www.truecrypt.org.

There is an app in the repositories that enables the user to create password-protected folders.  This app, cfs, is for creating encrypted partitions and filesystems.  And as a directory is a filesystem, cfs is good for our purpose.

cfs is a command-line utility.  Unfortunately, many newbies don’t like using the command-line interface.  But there’s no need to fear the CLI.  Here is a step-by-step tutorial on how to use cfs to create a password-protected directory.

First thing  we need to do is install cfs.  This can be done through Synaptic or with apt-get.  And as are going to be using a terminal for this procedure, we may as well start right now. So, open a terminal Applications > Accesories > Terminal and type in the command

sudo apt-get install cfs

Type in your password when prompted.  apt-get will ask if you want to install the other packages that cfs depends on – answer “y” to all this.  When cfs has been successfully installed, apt-get will exit and you’ll be returned to the command prompt.

There will now be several new commands available to you.  The ones we will need today are cmkdir, cattach and cdetach.

Now we need to create the encrypted directory. To do this, we will use the command cmkdir.  cfs will ask for a “key” – this is the pass phrase you will use to open the folder in the future, and must be at least 16 character long.  In this example I’m going to call my encrypted directory “lock”.

So, go to the location where you want to put the directory and create it,

user@ubuntu:~$ cmkdir lock
Key:
Again:
user@ubuntu:~$

So, the encrypted directory “lock” has been created in my home directory – ie ~/lock.  Now we want to put our secret files into it. This is done by attaching another directory to ~/lock. I’ll call this one “clock”, but you can call it whatever you like. cfs will ask for the key – this means the pass phrase you just made up.

user@ubuntu:~$ cattach lock clock
Key:
user@ubuntu:~$

If you look in the directory /crypt you will find the directory you just made – /crypt/clock.  This is where you want to put your secret files. You don’t put the files direcly into ~/lock.

user@ubuntu:~$ mv file1 file2 file3 /crypt/clock/
user@ubuntu:~$

Now, to close ~/lock so no one can get into it, we need to unattach the directory with the cdetach command.

user@ubuntu:~$ cdetach clock
user@ubuntu:~$

Do you want to check that your files are in ~/lock, and that they’re encrypted?  Well, let’s see a list of ~/lock’s contents:

user@ubuntu:~$ ls lock
19929910f65ed51c  1deec15b5201f48d  c8b70c7c5b4e5884

user@ubuntu:~$

So the file names have been encrypted too.  And what’s in them?

user@ubuntu:~$ cat lock/19929910f65ed51c
��A���3��<g�Y���f�h�RCC\��%v�|
AB�r��Ҍr�z���|�ݒy�mAp�’��܅�n�x����Y/Oªøù+¥Ö©õYŒ«Â┌&:/P⎻B®¯ò␍úX²…Æ¿␍␋€”Ç─◆¤/¦¤‰Š£ç≤¬¼=öπЉ/¡û™␍!L─≠⎻ž$/.€Ø<–)ù(î-ÈýÏþOø
”’8L„åD3&O0”Ç›5┌¦·1Þ_-R⎽û°8(Ôµ┬çH¸SȾ°␉⎽«¦S£ò?ÿßë´æ‘¡⎺V◆O├ä„E◆ì$VEM¨⎺†VüÔОÄ²ïÑ├] >(␤ ª@Õ呵┘¡•┬/‰éâ┌␌O±“Àâ0Q
IX\B¸6ž2SÁ␌åˆ
H◆?7¿C€#┘èÄSܵ€*?ŠÚB─šKõ‹·ù¾ˆ°ÃB£Êß9ÏU¢ȁ֌+(ëöQ®┐?:≥ÔI•D¡(‹ÚÁ;¿<(ÒÃ⎼ñC…•óI┌ÚMËÕ│S¾ÛüM®ŒÄÇ œÎ␋⎽Ñ◆┬’?    à‹Ì¢ý┌‹€SÉ└½€[¢‰⎼ˆ°ÿ ␌ºä┬üLÈW–ìHÖ¬◆Ô3à° ┌ϛ┼≠␋¶≠­/S-;·
ïŸ20áµïÍ£©≥ŒÔ␌␋—,┐š ├5´Ë²Â␌ß³≠¥–(¢]    ⎺æ≠·ÙU│àô
±├$
ŽÇ\     ÝQ⎻H@&␌┼└·├[³¯•ÓζGU
<snip>

When you want to access your secret files, or if you want to put more files into ~/lock, you must first reattach it, using cattach.  You move files in or out of the attached directory in /crypt – you never put files directory into ~/lock. Then when you’re finished, you retach using cdetachYou must never forget to detach if you want to keep the secret files secret.

——–

If you’ve got any questions or comments, don’t be shy!

_gos=’c4.gostats.com’;_goa=354450;
_got=2;_goi=2;_goz=0;_gol=’Free hit counter’;_GoStatsRun();
Free hit counter
Free hit counter

5 Responses to “Linux Tutorial: How to create a password-protected folder”

  1. sri krishna Says:

    thanks for the info…..
    but the link is going to http://www.truecryptorg/ instead of http://www.truecrypto.org
    and the new versions have a GUI

  2. Alexwebmaster Says:

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  3. alexfeng Says:

    sorry sri krishna…
    your link is going to http://www.truecrypto.org instead of http://www.truecrypt.org

    owned hehe

  4. ravishankar Says:

    i followed the above procedures and got locked myself inside,

    this is what i did

    1. cmkdir sensbackup
    key : 1234567890123456
    again : same

    2. created a folder test by mkdir test,and cattach sensbackup ./test

    3. key : same key

    4. now added a new file inside /crypt/test/sample.txt

    5. cdetach test

    6 now when i try to attach it says

    [14:09][root@Internalserver:~]$ cattach ./sensbackup/ ./test/
    Key:same key
    cattach: badly formed name

    how do i recover from this ?

  5. t0p Says:

    ravishankar: I don’t understand why you created the directory “test”. If you wanted to attach sensbackup to a directory called “test”, all you needed to do was give the command:

    cattach sensbackup test

    ie, there was no need to do “mkdir test”.

    These are the steps you should have done:

    1. cmkdir sensbackup (creates the encrypted directory “sensbackup”)

    2. cattach sensbackup test (attaches sensbackup to a directory /crypt/test)

    3. put file in /crypt/test

    4. cdetach test (detaches sensbackup from /crypt/test… so /crypt/test no longer exists)

    I advise you to delete sensbackup and test, then follow the steps outlined above.

Leave a Reply