selfjungle Just another WordPress weblog


LUKS with remote header, encrypted key

# create encrypted key
export GPG_TTY=$(tty) 
dd if=/dev/urandom bs=8388607 count=1 | gpg --symmetric --cipher-algo AES256 --output KEY.gpg
# allocate empty file for hader with size
truncate -s 2M HEADER.img

# NOTE: the LUKS header will be overriden with mkfs
gpg --decrypt KEY.gpg | cryptsetup --cipher serpent-xts-plain64 --key-size 512 --hash sha512 --header HEADER.img --key-file - luksFormat DEV

#check result (instead of DEv it is the header)
cryptsetup luksDump HEADER.img

#add fallback password if the KEYFILE is lost (to the header not to DEV)
mkfifo /tmp/gpgpipe 
gpg --decrypt KEYFILE | cat - >/tmp/KEYFILE2
cryptsetup --key-file /tmp/KEYFILE2 luksAddKey HEADER.img

rm -vf /tmp/KEYFILE2

gpg --decrypt KEY.gpg  | cryptsetup --header HEADER.img --key-file - open DEV enc

# and close
cryptsetup close enc

Tagged as: No Comments

block device from file

Mounting a loopback device.
In the kernel config, CONFIG_BLK_DEV_LOOP needs to be set.

# Check the used devices:
losetup -a
# Create the file
dd if=/dev/zero of=FILENAME  bs=1024k count=MEGABYTES
# Attach loopback device to file
losetup /dev/loopN FILENAME
# Creating filesystem on device
mkfs.ext3 /dev/loopN
# Mounting dev
mount /dev/loopN MOUNTPOINT

# umount
# detach
losetup -d /dev/loopN
Tagged as: No Comments

create file with given size (filled with zeros)

dd if=/dev/zero of=FILENAME  bs=1024k count=MEGABYTES
truncate -s 2M FILE
Tagged as: No Comments

replace string in dir

grep -rl STRING1 .  | xargs ^Cd -i 's/STRING1/STRING2/g'

Note: This replaces STRING1 to STRING2 even in hidden dirs, which can mess up your .git/index

Tagged as: No Comments

non interactive gdb to run & backtrace

set confirm off can turn off the "Quit anyway? (y or n)" question.

gdb EXECUTABLE  -ex "set width 1000" -ex "thread apply all bt" -ex run -ex bt -ex "set confirm off" -ex quit
Tagged as: , No Comments

update all packages under same category (for example KDE) with emerge

from eix --help:

 -#, --only-names       --pure-packages with format /
 -I, --installed       Next expression only matches installed packages.
 -C, --category          category

The emerge command:

emerge -av $(eix -I#C kde-base)
Tagged as: , No Comments

git auto-completion

wget -O ~/.git-completion.bash
source ~/.git-completion.bash
Tagged as: , No Comments

print range of lines of a file

Print from line N..M from FILE:

sed -n N,Mp FILE
Tagged as: No Comments

bash basics

Executing programs in parallel:

p1 ; p2 ; p3 ; ...

Note: use wait if inside a script, so it waits for each child to finish.

Executing programs sequentially:

p1 ; p2 ; p3 ; ...

Executing programs sequentially, stop if one fails:

p1 && p2 && p3 && ...
Tagged as: No Comments

bash case-insensitive filename tab-competion

Edit /etc/inputrc:

add this line:

set completion-ignore-case on
Tagged as: No Comments