How to change disk encrypted password

So here we are again, I encrypted my drive with luks however at some point I wanted to change the passwords.

Currently I’m not using any DE(desktop environment), I just use open-box, therefore I don’t have any of the nice gui utilities that come with Gnome or Kde.  I quickly search on google 🙂 for a solution and it turns out that it is pretty much straight forward, btw I ended up on this blog which actually present a quite better looking post. However this is meant to be just a quick reference. In any case you can man cryptsetup for more infos on the matter.

You need to identify the partitions/partition you would like to change the password to, a simple ls -l /dev/disk/by-id should list all the partitions as long as you are using udev. Or  you could type lsblk which will output something like this, according to your current pc configuration,

username@debian /etc :$ lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                     8:0    0 149.1G  0 disk  
├─sda1                  8:1    0  37.3G  0 part  
│ └─sda1_crypt (dm-0) 254:0    0  37.3G  0 crypt /
└─sda2                  8:2    0 111.8G  0 part  
  └─sda2_crypt (dm-1) 254:1    0 111.8G  0 crypt /home
sdb                     8:16   1   7.6G  0 disk  
└─sdb1                  8:17   1   7.6G  0 part  /boot

So once you know wich partition you want to change the password to just type

username@debian:~$ sudo cryptsetup luksAddKey /dev/sda1
Enter any passphrase:
Enter new passphrase for key slot:
Verify passphrase:

You must enter the current paraphrase and then type in the new one twice.

Once that’s done we can go ahead  and delete the old one. Type in the following

username@debian:~$ sudo cryptsetup luksRemoveKey /dev/sda1
Enter LUKS passphrase to be deleted:

Type the old password  and repeat the process if you have more than one encrypted partition and that’s it.

Adding trim support in LMDE/Ubuntu/Debian

Some time ago I bought a ssd drive and I wanted to preserve the drive
performance, therefore I tried to add the discard option in the fstab file,
however it turns out that it doesn’t really work on the newest filesystem (Btrfs)
which is the default filesystem for LMDE 14, I followed this guide, and when I tested it, didn’t work at all. Therefore I made a little script that runs
the ftrim command, then I added it to the crontab.

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import pynotify
import sys
import subprocess
import logging
import time
log_filename = '/var/log/trim_logs/PyTrim.log'
logging.basicConfig(filename=log_filename,level=logging.INFO)
dt = time.strftime(" %Y-%m-%d %H:%M:%S")

if __name__ == '__main__':
if not pynotify.init("Basics"):
sys.exit(1)

proc=subprocess.Popen('sudo fstrim -v / ', shell=True, stdout=subprocess.PIPE, )
output=proc.communicate()
output = str(output)[2:-10]
n = pynotify.Notification("PyTrim", output)
logging.info(output+dt)

if not n.show():
print "Failed to send notification"
sys.exit(1)

Running it from the command line ie “sudo f_trim” works quite well however in order to
run the ftirm command without superuser privileges you need to make a little modification
on the sudoers file, like this.

cd /etc/
sudo visudo -f sudoers

Those commands will open nano whith is the default editor for sudoers file and you will see
something like this:
sudoers
you need to change “yourusername” you login name then save it, Crtl+X and Yes to overwrite the old file
and enter to save it. If you don’t know how to use nano just google for a quick nano tutorial.
Next step is to add your script on to crontab, you if you want to look for a crontab tutorial
this is definitely a good resource, however the man pages and info files are your friends :D.
The following is a screen shot of how it looks on my system.

crontab

So you need to edit the crontab file with your favourite editor and add line like the last one you can see on the screen shot.
Since the script pipes the result to the notifications area it’s really important to add the line “env DISPLAY=:0” otherwise the notification won’t show up on the screen. Obviously the path in the crontab file must be changed accordingly to the path where you are keeping the script.
The last thing is to create a directory where you can save the logs. If you want to use /var/log/trim_logs/ as selected in line 10 you need to first create that directory and change it’s owner ship to yourself; one way to go is something like this:

cd /var/log
sudo mkdir trim_logs
sudo chown yourusername trim_logs

You can still choose another directory and modify line 10.
One last thing, once you save the script remember to make it executable
by running otherwise it won’t run.

chmod +x yourfilename

I hope this little post can help someone else. Feel free to post any questions.