DEV Community

M. Oly Mahmud
M. Oly Mahmud

Posted on • Edited 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

Go to the following link https://login.tailscale.com/admin/machines.
You will see a list of your devices connected to the Tailscale network. Click on the server name where you want to start the SSH server.

Go to the Access Controls tab and Edit the file.

Update the following section.

"ssh": [
        {
            "action": "accept",
            "src": ["autogroup:member"],
            "dst": ["autogroup:self"],
            "users": ["root", "autogroup:nonroot"]
        },
]
Enter fullscreen mode Exit fullscreen mode

Now, save the file.


Run the following command:

sudo tailscale up --ssh
Enter fullscreen mode Exit fullscreen mode

If you get the following message:

You are connected over Tailscale; this action will reroute SSH traffic to Tailscale SSH and will result in your session disconnecting.
To skip this warning, use --accept-risk=lose-ssh
aborted, no changes made

Run the following command:

sudo tailscale up --ssh --accept-risk=lose-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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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.

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay