Ssh – Cannot run cryptsetup throught SSH

luksssh

I'm trying to open a LUKS drive through SSH directly.

ssh root@XX "cryptsetup luksOpen /dev/sdb3 secure

But, no password prompt and it stuck.

debug1: Sending command: cryptsetup luksOpen /dev/sdb3 secure
debug2: channel 1: request exec confirm 1
debug2: callback done
debug2: channel 1: open confirm rwindow 0 rmax 32768
debug2: channel 1: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 1
debug2: exec request accepted on channel 1

Is that something impossible?

Best Answer

For the prompt to work, you need to add -t.

ssh -t root@host cryptsetup luksOpen /dev/thing luksthing

(It also works if you just type out your password when it's "stuck" waiting for input, but it will echo in your local terminal.)

Alternatively, piping the passphrase works well enough:

echo -n 'password' | ssh root@host cryptsetup luksOpen /dev/thing luksthing

And to prevent it leaking to the process list and command history, better put it in a file.

ssh root@host cryptsetup luksOpen /dev/thing luksthing < passwordfile

At which point you might just as well use a truly random keyfile rather than just a simple passphrase.

Related Question