Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using an Linux Mint Debian Edition. I would like to have a Truecrypt volume (either a file in my home directory or a separate partition) be automatically mounted on login using my login password. Is this possible? If not, how could I make it prompt for a password and mount directly after login?

share|improve this question
add comment

2 Answers 2

Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.

If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.

Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0

Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".

Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.

The simplest way of doing this is to use the Debian-specific command update-rc.d:

root@skx:~# update-rc.d blah defaults Adding system startup for /etc/init.d/blah ... /etc/rc0.d/K20blah -> ../init.d/blah
/etc/rc1.d/K20blah -> ../init.d/blah /etc/rc6.d/K20blah -> ../init.d/blah /etc/rc2.d/S20blah -> ../init.d/blah
/etc/rc3.d/S20blah -> ../init.d/blah /etc/rc4.d/S20blah -> ../init.d/blah /etc/rc5.d/S20blah -> ../init.d/blah

If you wish to remove the script from the startup sequence in the future run:

root@skx:/etc/rc2.d# update-rc.d -f blah remove update-rc.d: /etc/init.d/blah exists during rc.d purge (continuing) Removing any system startup links for /etc/init.d/blah ... /etc/rc0.d/K20blah
/etc/rc1.d/K20blah /etc/rc2.d/S20blah /etc/rc3.d/S20blah
/etc/rc4.d/S20blah /etc/rc5.d/S20blah /etc/rc6.d/K20blah

This will leave the script itself in place, just remove the links which cause it to be executed.

You can find more details of this command by running "man update-rc.d".

These are just examples. Just generate your own script to mount the volume and supply the password if you want. Of course if you do that then your password is stored in plaintext on your hdd. You can alter the script to prompt for a password of course.

Source

share|improve this answer
add comment

I think you would need to patch your login program(s) -- login, xdm/gdm/kdm, ... - to mount the volume or pass the inputted password to another process. Passing the password in clear form to another process seems a security risk. There is no wa

Prompting the password after login seems easy enough and more secure. There is just the minor nuisance of typing the password twice for the first login (or login after you decide to automatically or manually unmount the encrypted volume).

What the answer exactly looks like depends on your method of logging in. Each graphical desktop system probably have somewhat different method of specifying program to run. How to run commands as part of the login to your favorite GUI Desktop system is worth another distinct question. Essential to your current question is that you could create a script to check whether your Truecrypt volume is mounted and if not then mount it, and configure your login to run this script that would would look something as simple like the below:

#!/bin/sh

your_truecrypt_volume_mounted || mount_true_crypt_volume

where your_truecrypt_volume_mounted is a shell function or command to check if you have already mounted the encrypted volume (probably could just grep output of mount), and mount_true_crypt_volume is the command or shell function to mount your volume. If you are logging into a graphical desktop (Gnome/KDM/XFCE/whatever), you could run the mount command in terminal application so that the user can be prompted for password. You can use the DISPLAY environmental variable as a hint that you are running X Windows session or make it a command line option to the script if you want to reuse it (without specifying in multiple places your mount paths etc).

For login to virtual console, you could run the same script in your ~/.bash_login file, assuming the default bash is your shell.

You probably know already what the commands to mount Truecrypt volume and check for Truecrypt volume presence are.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.