Ubuntu: Mount Encrypted Home Directory (~/.private) From an Ubuntu Live CD

Recently my old desktop system crashed and I brought a new Ubuntu Laptop from Dell. To access my data from old hdd; I’ve attached my desktop harddisk using an external USB case. Now my old data is stored using external USB hard disk. How do I recover data from encrypted ~/.private home directory using an Ubuntu Live CD and copy it to existing laptop drive using known passphrase?

You can easily mount Ubuntu Encrypted Private or Encrypted Home directories from an Ubuntu LiveCD.

Step # 1: Boot From LiveCD

Use Ubuntu Live CD to boot system. Attach external USB hard disk to the system. If automouted just remove it.

Step # 2: Chroot To Old Hard Disk

Open terminal and type the following command to find USB device name:
$ sudo -s
# fdisk -l

Mount USB device at /media/chroot, enter:
# mkdir -p /media/chroot
# mount /dev/sdb1 /media/chroot

Replace /dev/sdb1 with actual USB device name.

Mount /proc file system inside /media/chroot

Type the following commands:
# D=/media/chroot
# mount -o bind /dev $D/dev
# mount -o bind /sys $D/sys
# mount -o bind /dev/shm $D/dev/shm
# mount -o bind /proc $D/proc

Optional give access to laptop hard disk inside chroot:
# mkdir $D/data
# mkdir /data-recovery
# mount --rbind /data-recovery $D/data

Chroot to $D

Type the following command to login into your old hard disk, enter:
# chroot $D
# su - username
# su - vivek

Replace vivek username with your actual username.

Mount Encrypted Home Directory

Type the following command:
$ ecryptfs-mount-private
The above will interactively prompt for the user’s login password. Once entered you can access data at /home/vivek:
$ df | grep vivek
$ cd /home/vivek
$ ls

How Do I Copy Data To Laptop?

Simply use cp or rsync command. Make sure laptop hard disk is also mounted from LiveCD:
$ cp -avr /home/vivek/data.dir/ /data
Make sure /data accessible inside chroot using the mount command (see above). When you exit from chroot jail, you should see your data at the following location:
# ls /data-recovery

How Do I Copy Data To Another System Over LAN?

Use rsync / scp / sftp command as follows:
$ rsync -av /home/vivek/data/dir1 [email protected]:/data/to/dest
$ scp /path/to/file [email protected]:/dest

References:

  • EncryptedPrivateDirectory topic from the official Ubuntu wiki.
  • man pages – mount, df, fdisk, su, sudo, and grep commands.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.