Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Last active February 13, 2024 17:00
Show Gist options
  • Star 49 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save proudlygeek/5721498 to your computer and use it in GitHub Desktop.
Save proudlygeek/5721498 to your computer and use it in GitHub Desktop.
Mount NFS Folder via SSH Tunnel

1. Install NFS on Server

Install the required packages (Ubuntu 12.04):

apt-get install nfs-kernel-server portmap

2. Share NFS Folder

Open the exports file:

vim /etc/exports

Add the following line:

/home/proudlygeek  localhost(insecure,rw,sync,no_subtree_check)

Restart NFS Service:

service nfs-kernel-server restart

or just export the FS:

exportfs -a

3. Install NFS Client

Install the client:

apt-get install nfs-common portmap

Make a mount folder:

mkdir /mnt/nfs-share

Setup an SSH tunnel (local-to-remote port):

ssh -fNv -L 3049:localhost:2049 user@hostname

Mount the folder:

mount -t nfs -o port=3049 localhost:/home/proudlygeek /mnt/nfs-share
@aure-olli
Copy link

I had to use localhost6 in /etc/exports for this to work. Weirdly, NFS recognize that localhost and localhost6 are the same (and only the first one will be used), but they are not equivalent.

/home/proudlygeek  localhost6(insecure,rw,sync,no_subtree_check)

@BilyZ98
Copy link

BilyZ98 commented Feb 12, 2022

One thing I am curious about is does the remote port has a specific meaning? is it a ssh port or is it just a random port ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment