Read more

Linux: Mount second encrypted HDD automatically without entering a password

Kim Klotz
March 21, 2012Software engineer at makandra GmbH

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"

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

After rebooting the harddisk should be mounted automatically

Posted by Kim Klotz to makandra dev (2012-03-21 13:28)