ssh, truecrypt, sshfs in a script

Hello all,

First time posting, although the site has helped solve many problems in the past!

I would like to create a script to simplify a series of commands that I run:

Log into the ssh-server (RSA key)

ssh username@hostname -p 6110

Once there, I mount a truecrypt volume:

truecrypt /media/uhd/container ~/mnt

After entering the password to complete the mount, I log out from the ssh-server

exit

I then mount those files locally:

sshfs username@hostname:~/mnt /media/remote -p 6110

Once I have finished working, I unmount the remote volume:

fusermount -u /media/remote

I then log back onto the ssh-server to unmount the truecrypt container:

ssh username@hostname -p 6110
truecrypt -d

I've made some simple scripts for vnc through ssh, but I've not managed to make much headway on scripting this.

I'm presuming I'll need two scripts: one to mount the truecrypt container and then mount that locally, and another script to dismount the remote container then dismount from truecrypt.

Any pointers on how to go about this would be very much appreciated! (and indeed whether I can refine the process)

-- Added with regard to alternative method --

Although I can mount the drive locally then use truecrypt locally:

sshfs -p 6110 username@hostname:/media/uhd/ /media/remote -o allow_other

The (lack of) speed in accessing the truecrypt contents makes it unworkable. I've put this down to the very slow server

---------- Post updated 04-06-11 at 03:44 AM ---------- Previous update was 04-05-11 at 02:05 PM ----------

Well, I'm still not getting very far with this one.
If I try the following:

#!/bin/bash
ssh -v -p 6110 username@hostname 'truecrypt /media/uhd/container ~/mnt'

It just hangs indefinitely after sending command: truecrypt /media/uhd/container ~/mnt ... which is the point at which I would be expected to enter the truecrypt container's password.

Any clues on what I can do in order to get the password prompt?

I don't have truecrypt, but a well written program will open /dev/tty and communicate with it to obtain a password from a user. When you run a command remotely via ssh you won't have a controlling terminal so that is not possible. If you're willing to compromise security in the name of automation, your local script could obtain a password from the user and then pass it to truecrypt on the command line.

Your alternate method of running truecrypt locally seems to be the very best approach. It doesn't make sense that it would be slow unless the server is able to run truecrypt very quickly and the local machine is very slow or resource-limited.

Since the data is already encrypted, maybe you could serve it with NFS instead of SSH.

Are both machines running Linux?

BTW, Fedora Linux renames truecrypt to realcrypt.

Thank you for the reply. I think that is the bit I was missing (and hence going around in circles) - the lack of a controlling terminal. I will certainly look into the alternative you describe and see how much security is compromised.

Thank you for your reply too. I definitely think the server is the weak link (533mhz via epia!) and struggles with most tasks, whereas I have no issues handling the truecrypt volumes on my local machine. However, the container is very large (75gb) so I'm not sure how the decryption works when the encrypted volume is locally mounted :confused: It certainly isn't sending the whole container over before decrypting!

Both are running linux (ubuntu 10.10 and debian squeeze)

Perhaps a server upgrade is in order...