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 book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
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)