Skip to content

ansmirnov/linux-encrypted-directory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Create an encrypted home directory on Linux

Contents

System environment

  • CentOS 8.1

System preparation

yum install cryptsetup

Parameters

Set the size of the encrypted container in megabytes.

SIZE=1024

Set the path to the encrypted container.

CONTAINER=/root/data.bin

Set the filesystem.

FILESYSTEM=ext3

Set the container ID.

MOUNT_ID=homedir

Set the mount directory.

MOUNT_DIR=/home/

Create a container

This command can be executed for a long time.

dd if=/dev/urandom of=$CONTAINER bs=1M count=$SIZE

Encrypt the container

Answer the question and enter the encryption password.

cryptsetup -y luksFormat $CONTAINER

Make a file system in the container

cryptsetup luksOpen $CONTAINER $MOUNT_ID
mkfs -t $FILESYSTEM -j /dev/mapper/$MOUNT_ID
cryptsetup luksClose $MOUNT_ID

Commands for mounting and umounting

Mount container

echo "cryptsetup luksOpen $CONTAINER $MOUNT_ID && mount /dev/mapper/$MOUNT_ID $MOUNT_DIR"

Umount container

echo "umount $MOUNT_DIR && cryptsetup luksClose $MOUNT_ID"