How to Encrypt your VPS disk (VPS) or Dedicated Server with Cryptsetup

📒  Dedicated Servers

How to Encrypt your VPS disk (VPS)

Encrypting a Linux virtual server offers paramount benefits for data security. By implementing encryption, sensitive information stored on the server becomes indecipherable to unauthorized access. This crucial security measure safeguards against data breaches, unauthorized access, and potential cyber threats. Encrypting the server ensures the confidentiality and integrity of stored data, mitigating risks associated with data leaks or unauthorized modifications.

Note: Make sure that you use the right Linux Distribution for such purpose, knowledge is required. Please make a backup before doing anything related to encryption.

Encrypting your VPS disk

What is Cryptsetup?

Cryptsetup is an open-source utility that enables users to set up disk encryption on Linux systems, providing a robust layer of protection for stored data. By leveraging the Linux Unified Key Setup (LUKS) standard, Cryptsetup ensures a seamless and secure encryption process.

Key Features of Cryptsetup:

  1. Data-at-Rest Protection: Cryptsetup encrypts entire disk partitions, safeguarding data at rest. This ensures that even if unauthorized access occurs, the encrypted data remains indecipherable without the correct encryption key.
  2. Transparent Operation: Operating transparently in the background, Cryptsetup seamlessly integrates with the Linux system, allowing users to access their data without hindrance once authenticated.
  3. LUKS Standard Compliance: Cryptsetup adheres to the LUKS standard, providing a unified and widely accepted method for managing disk encryption on Linux. This standardization facilitates compatibility and interoperability across various Linux distributions.
  4. Flexibility in Key Management: Users have the flexibility to employ various authentication methods, including passphrases, key files, or even a combination of both. This adaptability enables users to choose the most suitable authentication mechanism for their security needs.

Why Choose Cryptsetup?

  1. Robust Encryption: Cryptsetup utilizes advanced encryption algorithms, such as AES, ensuring a high level of security against potential threats. This robust encryption mechanism is crucial for protecting sensitive data from unauthorized access.
  2. Comprehensive Security Solution: As a comprehensive solution, Cryptsetup addresses the need for holistic data security. It encrypts entire disk partitions, preventing unauthorized access not only to specific files but to the entire storage medium.
  3. Open-Source Reliability: Being open-source, Cryptsetup benefits from continuous community scrutiny and development. This transparency enhances trust in the tool’s reliability, making it a preferred choice for security-conscious Linux users.
  4. Adherence to Best Practices: Cryptsetup follows best practices in disk encryption, ensuring a secure and standardized approach. Its adherence to the LUKS standard reflects a commitment to industry-accepted security protocols.

In conclusion, Cryptsetup emerges as an indispensable tool for individuals and organizations seeking to bolster the security of their Linux systems. By providing robust data encryption through the LUKS standard, Cryptsetup delivers a comprehensive solution that aligns with best practices, offering peace of mind in an ever-evolving digital landscape.


Encrypting a Linux VPS (Virtual Private Server) typically involves encrypting the file system to protect data at rest. The most commonly used tool for this purpose is LUKS (Linux Unified Key Setup). Here’s a step-by-step guide on how to encrypt a Linux VPS using LUKS:


Note: This process involves modifying disk partitions and encrypting data, which can result in data loss if not done carefully. Make sure you have a backup of important data before proceeding.

Step 1: Backup Important Data

Before you start, ensure that you have a backup of your important data. Disk encryption is a powerful tool, but mistakes can result in data loss.

Step 2: Update and Upgrade

Make sure your system is up-to-date:

sudo apt update

sudo apt upgrade


Step 3: Install Required Packages

Install the necessary packages, including cryptsetup, which is used for LUKS:

sudo apt install cryptsetup


Step 4: Partition the Disk

You need an unencrypted partition for the bootloader and the /boot directory. Typically, this partition is not encrypted to allow the system to boot.

Use a partitioning tool like fdisk or parted to create partitions. For example:

sudo fdisk /dev/sdX


Create a new partition for /boot (non-encrypted), and another one for the encrypted root file system.

Step 5: Encrypt the Partition

Use cryptsetup to encrypt the partition:

sudo cryptsetup luksFormat /dev/sdXY


You will be prompted to enter a passphrase. This passphrase will be required to unlock the encrypted partition during boot.

Step 6: Open the Encrypted Partition

After formatting, open the encrypted partition:

sudo cryptsetup luksOpen /dev/sdXY my_encrypted_partition


Step 7: Create File System on Encrypted Partition

Create a file system on the encrypted partition. For example, if using ext4:

sudo mkfs.ext4 /dev/mapper/my_encrypted_partition


Step 8: Mount the Encrypted Partition

Mount the encrypted partition:

sudo mount /dev/mapper/my_encrypted_partition /mnt


Step 9: Copy Data

If you have an existing system, copy the data to the encrypted partition:

sudo rsync -av --exclude=/mnt --exclude=/dev --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/run / /mnt


Step 10: Update /etc/fstab

Update /etc/fstab to reflect the changes. Replace the old root partition with the new encrypted one.

Step 11: Update GRUB

Update the GRUB configuration to include the encrypted root partition. Run:

sudo update-grub

Step 12: Reboot

Reboot your system and make sure it boots successfully with the encrypted partition.

Step 13: Test

After rebooting, test that everything works as expected. Ensure you can unlock the encrypted partition using the passphrase.

Remember, this is a simplified guide, and the exact steps may vary based on your distribution and server setup. Always refer to your distribution’s documentation for any specific instructions or considerations.

WARNING: We allow you to encrypt your own Virtual Server (VPS) and Dedicated Server, but Alexhost is not responsible for any data loss that may occur in your server(s). Alexhost also can’t restore your server after encryption. In this scenario you are the only responsible for that. We recommend you make backups before doing anything related with Encryption.