Mount your home directory with SSHFS in Linux
By Mikael Ståldal
If you have your home directory on another machine, it’s common to use NFS to access it. NFS is easy to set up and works more or less out of the box on Linux. However, NFS is not secure, and you need to have a carefully setup firewall in order to use it safely.
SSHFS is a more secure alternative, but it’s quite tricky to set up on the client side. It’s very easy to set up on the server though, you just need an SSH server with SFTP support.
This is the way to set up it on the client using Ubuntu desktop 10.04:
- First you have to get rid of the file
.ICEauthority
from your home directory. Create a.gnomerc
file in your home directory:
mkdir "/tmp/.ICE-${USER}"
export ICEAUTHORITY="/tmp/.ICE-${USER}/.ICEauthority"
- Then you need to setup a local bootstrap home directory containing this
.gnomerc
file and your.ssh
directory including your private key file. The remote home directory will be mounted over this. This can be on a read-only filesystem. You need to modify your.ssh/config
file to explicitly point out your private key and known hosts files, add this:
IdentityFile /home/username/.ssh/identity
IdentityFile /home/username/.ssh/id_rsa
IdentityFile /home/username/.ssh/id_dsa
UserKnownHostsFile /home/username/.ssh/known_hosts
- Setup mounting on login by adding this to
/etc/gdm/PostLogin/Default
:
sshfs -F ${HOME}/.ssh/config -o nonempty -o allow_other -o default_permissions ${USER}@theserver: ${HOME}
- Setup umounting on logout by adding this to
/etc/gdm/PostSession/Default
fusermount -u -z ${HOME}