cryptsetup-ssh - Linux


Overview

Cryptsetup-ssh is a command-line utility that allows you to securely map a remote disk over SSH. It encrypts volumes using a passphrase and opens them automatically when the SSH connection is established.

Syntax

cryptsetup-ssh [options] <subcommand> [arguments]

Subcommands

  • attach: Attach remote disk.
  • detach: Detach remote disk.
  • switch: Attach/detach on demand.
  • open: Open remote disk manually.
  • close: Close remote disk manually.
  • init: Initialize remote disk.
  • destroy: Destroy remote disk.
  • resize: Resize remote disk.

Options/Flags

  • -s, –source: Remote host IP address or hostname.
  • -p, –port: SSH port number. Default: 22.
  • -u, –user: SSH username.
  • -P, –passphrase: Passphrase for encrypted volume (stdin if not specified).
  • -f, –filesystem: Filesystem used in remote disk. Default: ext4.
  • -i, –init: Initialize remote disk with LUKS.
  • -d, –destroy: Destroy remote disk.

Examples

Attach Remote Disk with Passphrase:

cryptsetup-ssh attach -s host.example.com my-disk

Attach with Automatic SSH Key Authentication:

ssh-copy-id user@host.example.com
cryptsetup-ssh attach -s host.example.com my-disk -u user

Initialize Remote Disk with LUKS:

cryptsetup-ssh init -s host.example.com my-disk

Common Issues

  • Connection Refused: Ensure SSH is running on the remote host and that the SSH key is authorized.
  • Authentication Failed: Verify the SSH user and passphrase.
  • Could Not Open Remote Disk: Check if the SSH connection is stable and the remote disk is not already in use.

Integration

Cryptsetup-ssh can be combined with cron jobs or systemd units to automatically attach/detach disks based on scheduled tasks or events.

Related Commands

  • cryptsetup: Control encrypted volumes on local systems.
  • sshfs: Mount remote filesystems over SSH.