DEV Community

M. Oly Mahmud
M. Oly Mahmud

Posted on

Mounting The Filesystem of Nix OS Dev Sandbox Server to The Local Computer Using Tailscale and SSH

Nix OS is an innovative Linux distribution designed for developers, featuring declarative configurations and reproducible builds. When working with a Nix OS development sandbox server, you may need to access its filesystem directly from your local computer. This article will guide you through securely mounting the server’s filesystem using Tailscale and SSH.

Prerequisites

Before proceeding, ensure you have the following:

  • A Nix OS development sandbox server with Tailscale installed and running.
  • A Tailscale account and the Tailscale client installed on your local computer.
  • sshfs installed on your local computer for filesystem mounting.

Step 1: Install and Configure Tailscale

Open the dev.nix file and edit the following section:

packages = [
    # other packages
    pkgs.tailscale
  ];
Enter fullscreen mode Exit fullscreen mode

Then rebuild the container.

Step 2: Start the Tailscale

We have assumed that systemd is not installed on the server. So, we need to start the server manually. Run the following command.

tailscaled --tun=userspace-networking &
Enter fullscreen mode Exit fullscreen mode

Note: **--tun=userspace-networking is required because Cloud Shell lacks the permissions to manage kernel tun devices.**

Step 3: Login to Tailscale

Now, log in to your Tailscale account to attach the server to the Tailscale network.
Open a new terminal and run the following command:

tailscale login
Enter fullscreen mode Exit fullscreen mode

You will get a link to log in to your Tailscale account. Copy the link to a new browser tab then log in to your account.

Step 4: Start The Server with SSH Feature

Run the following command:

tailscale up --ssh
Enter fullscreen mode Exit fullscreen mode

It will enable SSH on the server

Step 5: Grab The IP Address of The Server

Tailscale has assigned the server an IP address. To get the address, run the following command.

tailscale ip
Enter fullscreen mode Exit fullscreen mode

You will get two IP addresses listed: the IPV4 address and the IPV6 address.
Copy the IPV4 address (on the first line).

Step 6: Connect The SSH Server from The Local Computer

On your local computer install Tailscale and login to the same account.

Install sshfs according to your Operating System. `sshfs allows you to mount a remote filesystem over SSH.

To connect to the server using SSH, run the following command.


tailscale ssh username_on_the_server@server_ip_address

Now, we will be able to connect to the server using SSH.

Step 7: Mount the File System

Make a directory server-storage inside the home directory of the local computer.

Assuming, the username on the server is user and the local computer username is mugdho.

We will mount the /home/user/ directory from the server onto the /home/mugdho/server-storage directory.

To mount the storage, open a new terminal and run this command.


sshfs user@server-ip:/home/user/ /home/mugdho/server-storage/

Done!
Now, we can use the server file system in the server-storage directory.

Conclusion

This setup allows you to work with server files as if they were local, enhancing productivity and flexibility.

Top comments (0)