Linux: Mount second encrypted HDD automatically without entering a password

Posted About 12 years ago. Visible to the public.

This is one possibility to do this. There are other and maybe even better ways to do this.

  1. Generate a key for your encrypted harddisk:

    dd if=/dev/random of=/home/bob/keyfile_sdb1 bs=4096 count=1
    
  2. Then add your keyfile to encrypted harddisk: How to change your dm-crypt passphrase (step 3)

  3. Create a mountpoint:

    mkdir /mnt/space
    
  4. Create a script e.g. in your homedirectory (/home/bob/mount_sdb1.sh):

    #!bin/bash
    
    #open harddisk
    sudo /sbin/cryptsetup --key-file /home/bob/keyfile_sdb1 luksOpen /dev/sdb1 sdb1_crypt
    #mount decrypted harddisk
    sudo /bin/mount /dev/mapper/sdb1_crypt /mnt/space
    
  5. Add this line to your /etc/sudoers that you must not enter a password

    %admin ALL=(ALL) NOPASSWD:/sbin/cryptsetup, /bin/mount    
    
  6. Add this script to "System - Einstellungen - Startprogramme"

After rebooting the harddisk should be mounted automatically

Last edit
Almost 12 years ago
License
Source code in this card is licensed under the MIT License.
Posted by Kim Klotz to makandra dev (2012-03-21 12:28)