2013-09-19

How to unlock encrypted file system on Linux automatically


  1. create a keyfile with random content
  2. $ sudo su -
    $ dd if=/dev/random of=/root/keyfile bs=1024 count=4
  3. Add the file to LUKS
  4. $ cryptsetyp luksAddKey /dev/sdb1 /root/keyfile
  5. Edit /etc/crypttab
  6. $ sdb1_crypt /dev/sdb1 /root/keyfile luks
  7. Edit /etc/fstab
  8. /dev/mapper/sdb1_crypt /media/Repository ext4 defaults 0 2
  9. Reboot or Remount

2013-08-27

Ternary operator(?:) in bash

Ternary operator is a short form of if/then/else
case $a in
    1) b=$c ;;
    *) b=$d ;;
esac

[[ $a=1 ]] && b=$c || b=$d
# At this case, 3rd part can be executed in case 2nd part fails

[[ $a=1 ]] && { b=$c; true; } || b=$d
# to avoid executing 3rd part by accident when 2nd part fails
## semicolon(;) is needed in {}