Encryption at rest protects stored data from unauthorized access even if the underlying storage medium is somehow accessed directly — a common requirement across many compliance frameworks. This guide covers what it means and practical implementation on a VPS.
What "At Rest" Means
"At rest" refers to data in storage (on disk) as opposed to data "in transit" (moving across a network) — both need protection, but through different mechanisms; this article focuses specifically on the at-rest piece.
Why Encryption at Rest Matters
Without it, anyone who gains access to the underlying storage — through a stolen/discarded physical drive, unauthorized server access, or certain backup exposure scenarios — can potentially read sensitive data directly, bypassing your application's normal access controls entirely.
Approach 1 — Full Disk Encryption
Encrypts the entire disk/volume at the OS level — protects against physical disk theft or unauthorized low-level access, though data is decrypted and readable to any process running on the server once it's booted and unlocked.
sudo apt install cryptsetup -y
Full disk encryption setup typically needs to be configured at OS installation time; consult your specific Linux distribution's installation documentation for LUKS-based full disk encryption if this is your chosen approach.
Approach 2 — Database-Level Encryption
Most major databases support transparent data encryption at the database level:
# MySQL/MariaDB example
ALTER TABLE sensitive_data ENCRYPTION='Y';
Encrypts data specifically within the database, independent of underlying disk encryption — check your specific database version's documentation for exact syntax and requirements.
Approach 3 — Application-Level Field Encryption
const crypto = require('crypto');
function encryptField(text, key) {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return iv.toString('hex') + ':' + encrypted;
}
Encrypts specific sensitive fields within your application before storage — the most granular approach, useful for particularly sensitive individual fields (e.g. SSNs, specific financial data) even within an otherwise unencrypted database.
Approach 4 — Encrypted Object Storage
Most S3-compatible object storage supports server-side encryption — see How to Set Up Self-Hosted S3-Compatible Object Storage with MinIO for self-hosted options, or check your chosen storage provider's encryption configuration options.
Key Management: The Critical, Often-Overlooked Piece
Encryption is only as secure as your key management — storing encryption keys alongside the encrypted data (e.g. in the same database, or hardcoded in application config) significantly undermines the protection. See How to Manage Environment Variables and Secrets on a VPS, and consider a dedicated secrets manager for genuinely sensitive encryption keys.
Encrypting Backups
See Backup Encryption: Protecting Your Backups from Unauthorized Access — backups containing sensitive data need the same encryption rigor as the live data, a commonly overlooked gap.
Performance Considerations
Modern encryption (AES-based, hardware-accelerated on most current CPUs) has minimal performance overhead for most workloads — rarely a valid reason to skip encryption for sensitive data.
Choosing the Right Approach for Your Situation
Full disk encryption provides broad, simple protection; database/field-level encryption provides more granular control appropriate for specific highly sensitive data — many compliance-conscious deployments layer multiple approaches rather than relying on just one.
Common Errors
Encryption keys stored in the same location as encrypted data — defeats much of the purpose; keys should be managed separately with their own access controls.
Continue Reading
- How to Manage Environment Variables and Secrets on a VPS
- Backup Encryption: Protecting Your Backups from Unauthorized Access
- How to Set Up Self-Hosted S3-Compatible Object Storage with MinIO
Browse more articles in Compliance & Industry-Specific Hosting.