This course is using an outdated version of the technology and is now considered to be Legacy content. It will be removed from our catalog on June 28, 2024. Please be sure to complete your course and finish any remaining labs before that date. We recommend moving to version 9.2, which is the latest version currently available.
In this exercise, you will create a new encrypted partition with LUKS. You will then open it, format it with an XFS file system, and demonstrate that you can mount it. Finally, you will unmount the file system and close the partition.
Outcomes
You should be able to encrypt a partition with LUKS.
Verify that workstation and servera are started.
Log in to workstation as student using student as the password.
On workstation, run lab luks-manage setup to verify that the environment is ready.
[student@workstation ~]$lab luks-manage setup
Verify that an additional disk is available on servera.
In this exercise, you use this disk to create an encrypted partition.
Log in to servera as student.
No password is required.
[student@workstation ~]$ssh student@servera[student@servera ~]$
Use the sudo -i command to change to the root user.
Use student as the password.
[student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Verify that the vdb disk is available, and has no partition.
[root@servera ~]#parted -l...output omitted... Error: /dev/vdb: unrecognised disk label Model: Virtio Block Device (virtblk) Disk /dev/vdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags:
Create a partition on the additional disk on servera.
Use the parted command to create a partition on the additional disk on servera.
Use the whole disk for the partition.
[root@servera ~]#parted /dev/vdb \>mklabel msdos \>mkpart primary xfs 1M 1G...output omitted...
Verify that the partition is available.
[root@servera ~]#parted /dev/vdb printModel: Virtio Block Device (virtblk) Disk /dev/vdb: 1074MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 1074MB 1073MB primary
Encrypt the vdb1 partition with LUKS.
[root@servera ~]#cryptsetup luksFormat /dev/vdb1WARNING! ======== This will overwrite data on /dev/vdb1 irrevocably. Are you sure? (Type uppercase yes):YESEnter passphrase:redhatRHTVerify passphrase:redhatRHT
Name the encrypted partition encryptedvdb1.
Use the cryptsetup luksOpen command to map the encrypted partition to the logical device encryptedvdb1.
[root@servera ~]#cryptsetup luksOpen /dev/vdb1 encryptedvdb1Enter passphrase for /dev/vdb1:redhatRHT
Verify that the partition is now available at /dev/mapper/encryptedvdb1.
[root@servera ~]#ls /dev/mapper/encryptedvdb1/dev/mapper/encryptedvdb1
Create an XFS file system on the encrypted partition, and mount this file system on the /encrypted directory.
When done, create a file in that directory.
Create an XFS file system on the /dev/mapper/encryptedvdb1 device.
[root@servera ~]#mkfs.xfs /dev/mapper/encryptedvdb1...output omitted...
Create the /encrypted directory.
[root@servera ~]#mkdir /encrypted
Mount /dev/mapper/encryptedvdb1 on the /encrypted directory.
[root@servera ~]#mount -t xfs /dev/mapper/encryptedvdb1 /encrypted
Verify that the /dev/vdb1 partition is correctly mounted.
[root@servera ~]#mount | grep /encrypted/dev/mapper/encryptedvdb1 on /encrypted type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Create a file in the /encrypted directory.
[root@servera ~]#touch /encrypted/testfile
Unmount the file system and lock the encrypted partition.
Unmount the file system from the /encrypted directory.
[root@servera ~]#umount /encrypted
Lock the encrypted partition.
[root@servera ~]#cryptsetup luksClose encryptedvdb1
Log out from servera.
[root@servera ~]#logout[student@servera ~]$logout[student@workstation ~]$