# Configure and access shared folders on Linux

In this article, you will learn how to set up a shared folder on Linux and access another device's shared folder from a Linux device.

{% hint style="info" %}
**Note**

For this procedure, Ubuntu 24.04 LTS is used as an example.
{% endhint %}

## Prerequisites

Before you begin, download and prepare the [Samba](https://www.samba.org/) app on your Linux device. Samba uses the [SMB](https://nordvpn.com/blog/what-is-smb/) protocol to share resources over the network. If you want to configure a shared folder using the GUI, you should also install the [nautilus-share](https://packages.ubuntu.com/noble/nautilus-share) package.

<details>

<summary>Install Samba</summary>

To install Samba, on your system:

1. Open **Terminal**.
2. Run the following command, which will fetch updates from your repositories and install Samba:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt update &#x26;&#x26; sudo apt install samba -y
   </code></pre>

</details>

<details>

<summary>Enable Samba authentication</summary>

To secure access to your shared folders, you need to create a Samba password.

1. Open **Terminal**.
2. Run the command below, which will prompt you to create a new Samba password for your current user:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo smbpasswd -a $USER
   </code></pre>

   &#x20;
3. Enter and confirm your new password.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Flsv0SraH0Ikql95kS1k1%2Flinux_smb_pwd.png?alt=media&#x26;token=ccbe94d5-43a1-4ae6-98d6-1c989afd6898" alt="Terminal output asking for the SMB password."><figcaption></figcaption></figure></div>

   &#x20;
4. Add your current user to the `sambashare` group with this command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo usermod -aG sambashare $USER
   </code></pre>

   &#x20;
5. Restart your PC.

</details>

<details>

<summary>GUI only: Install nautilus-share</summary>

The `nautilus-share` extension adds folder-sharing options to the system's context menu allowing convenient setup.

1. Open **Terminal**.
2. Install `nautilus-share` by running the command below:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt install nautilus-share -y
   </code></pre>

   &#x20;
3. To activate the extension you need to restart the Nautilus processes. Use this command to quit Nautilus:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nautilus -q
   </code></pre>

   &#x20;\
   Next time you open the **Files** app, Nautilus will start automatically.

</details>

## Configure a shared folder

Depending on your system, you may opt to configure a shared folder using the operating system's file manager or by using the command line.

{% tabs %}
{% tab title="GUI" %}
To create a network share using a file manager's network-sharing options:

1. Right-click the folder you want to share and choose **Sharing options**.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fl0dJSGF104dlI8bnyayO%2Flinux_smb_context_dark.png?alt=media&#x26;token=8d4bbb27-e0f3-44c6-8b33-1fb294112a54" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FUSVZjyK3jaW4tddJIuea%2Flinux_smb_context.png?alt=media&#x26;token=3cc7f306-cf17-4d93-81f2-ee3a2d8a48fe" alt="Selecting &#x22;Sharing options&#x22; from the context menu." width="375"></picture><figcaption></figcaption></figure></div>

   &#x20;
2. Select **Share this folder**, and, if needed, enter a custom name for your network share.
3. Click **Create share**.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FtuuvvmG4IrkZpqjLl0r7%2Flinux_smb_create_dark.png?alt=media&#x26;token=dc962685-dca7-4bad-8e3f-f29f8d6762e3" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FO54Uf4jU1OD7OfO3IL1R%2Flinux_smb_create.png?alt=media&#x26;token=776c0103-fbc6-4d6e-b414-c05cc1527820" alt="&#x22;Create share&#x22; buttong highlighted." width="375"></picture><figcaption></figcaption></figure></div>

{% endtab %}

{% tab title="Terminal" %}
Take the following steps to share a folder via the command line:

1. Open **Terminal**.
2. Navigate to the folder that you want to share and print out its absolute path by using the `pwd` command.\
   &#x20;

   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">/home/meshnet/Desktop/MeshnetFolder
   </code></pre>

   &#x20;

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FBRvoExYw5VOmbPp7VlDa%2Flinux_smb_pwd.png?alt=media&#x26;token=de341b07-31f1-41a6-9d28-97c493cab3f1" alt="Output of &#x27;pwd&#x27; command"><figcaption></figcaption></figure></div>

   &#x20;
3. Run the following command to open the Samba configuration file using the Nano text editor:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nano /etc/samba/smb.conf
   </code></pre>

   &#x20;
4. At the end of the file, append the following lines where `<ShareName>` is the name for your network share and `</path/to/folder>` is the absolute path of the folder from step 2:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">[&#x3C;ShareName>]
   path = &#x3C;/path/to/folder>
   read only = no
   browsable = yes 
   </code></pre>

   &#x20;

   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F5V8Z086Ts7894FAPT2Vk%2Flinux_smb_conf.png?alt=media&#x26;token=dc4729aa-868a-4058-8ad8-39f1140a2038" alt="Samba configuration file with the changes for the shared folder."><figcaption></figcaption></figure></div>

   &#x20;
5. Press **Ctrl** + **X**, **Y**, and **Enter** to save changes and exit.
6. Run the following command to restart the Samba process:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo systemctl restart smbd
   </code></pre>

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Note**

To access the shared folder, the peer device will need to use your Linux username and the previously created Samba password for authentication.
{% endhint %}

## Access shared folders

{% hint style="info" %}
**Note**

You can find platform-specific instructions for accessing the shared folder in the appropriate guides:

* [Access shared folders from Windows](https://meshnet.nordvpn.com/how-to/remote-files-media-access/configure-and-access-shared-folders-on-windows#access-shared-folders)
* [Access shared folders from macOS](https://meshnet.nordvpn.com/how-to/remote-files-media-access/configure-and-access-shared-folders-on-macos#access-shared-folders)
* [Access shared folders from Android](https://meshnet.nordvpn.com/how-to/remote-files-media-access/set-up-folder-sharing/access-shared-folders-on-android)
* [Access shared folders from iPhone/iPad](https://meshnet.nordvpn.com/how-to/remote-files-media-access/set-up-folder-sharing/access-shared-folders-on-ios)
* [Access shared folders from Android TV](https://meshnet.nordvpn.com/how-to/remote-files-media-access/set-up-folder-sharing/access-shared-folders-from-android-tv)
  {% endhint %}

Most Linux file managers let you directly access files shared on other devices. In this example, you will learn how to access a network share using GNOME Files.

1. Run the `nordvpn meshnet peer list` command and copy the Nord name of the sharer's device.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Flu7jFRKTlldabekqtXkg%2Flinux_peer_name_himalayas.png?alt=media&#x26;token=1cfabc26-9741-44b9-b170-50b24e9f0d8b" alt="Terminal output of the &#x27;nordvpn meshnet peer list&#x27; command with a peer device&#x27;s Nord name underlined."><figcaption></figcaption></figure></div>

   &#x20;
2. Open GNOME **Files** and select **Other locations** in the sidebar.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FH7l4sdfFGJyEfUT37rLi%2Flinux_smb_other_locations_dark.png?alt=media&#x26;token=91e5f164-1ece-4bd3-870d-1cbfcc3169bf" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FuiZAfmUDF5drKDJrgsGL%2Flinux_smb_other_locations.png?alt=media&#x26;token=780fa3db-a209-471f-9e5a-5e5b8ee1cd5d" alt="&#x22;Other locations&#x22; option highlighted." width="278"></picture><figcaption></figcaption></figure></div>

   &#x20;
3. In the **Enter server address** field at the bottom, type in`smb://`, paste the copied Nord name, add a slash (/) followed by the network share name, and click **Connect**.\
   &#x20;\
   **Example**

   `smb://secret.meerkat-himalayas.nord/MeshnetFolder`\
   &#x20;

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FFy9OUCijRwLNFv2ZDnrV%2Flinux_smb_connect_dark.png?alt=media&#x26;token=bd94edf2-6214-4435-af41-0cc1ae7b9435" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FWrfXZlUK6D2xmE5Blo54%2Flinux_smb_connect.png?alt=media&#x26;token=f70b23e0-9f46-435b-a401-e2a6952537d4" alt="Shared folder&#x27;s network path entered in the file manager."></picture><figcaption></figcaption></figure></div>

   &#x20;
4. Select **Registered user** and enter the username and password for accessing the shared folder.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F9LXYg9z1q1BRmMtG3O5H%2Flinux_smb_auth_dark.png?alt=media&#x26;token=71f7aad5-ce9d-47b1-a48c-31718d7eec3a" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FlFjNyJfIBrUUfJTs4Mb9%2Flinux_smb_auth.png?alt=media&#x26;token=21a95951-20b9-41a0-8c36-010793dd4850" alt="" width="563"></picture><figcaption></figcaption></figure></div>

   &#x20;
5. Click **Connect**.

The shared folder should now open in the file manager.

## Mount a shared folder

The shared folder you connect to becomes unavailable after a system restart, which means that you would need to reconnect to the folder each time you wish to access the files stored in it. However, by utilizing [CIFS](https://wiki.samba.org/index.php/LinuxCIFS_utils), you can mount the shared folder directly on your system and use it as a persistent storage location.

### Prepare a mounting point

1. Open **Terminal**.
2. Fetch repository updates and install CIFS by entering the following:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt update &#x26;&#x26; sudo apt install cifs-utils -y
   </code></pre>

   &#x20;
3. Create a new directory using the `mkdir` command, where you want to mount the shared folder.\
   &#x20;\
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">mkdir SharedFolder
   </code></pre>

   &#x20;
4. Navigate to the newly created folder using the `cd` command and print out its full path using the `pwd` command.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F7YkyZs9YWac6o9il1bab%2Flinux_smb_mount_point.png?alt=media&#x26;token=2f4e8337-e8ac-4bfe-b865-0355619d42ba" alt="Ouput of &#x27;pwd&#x27; command"><figcaption></figcaption></figure></div>

   &#x20;
5. Check your user ID number by executing this command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">echo $UID
   </code></pre>

### Edit the file system table

1. Open the `fstab` file with root privileges using the Nano text editor by running this command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nano /etc/fstab
   </code></pre>

   &#x20;
2. At the end of the file, append the following line for the shared folder:

   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">//&#x3C;NordName>/&#x3C;ShareName> &#x3C;/path/to/folder> cifs username=&#x3C;USERNAME>,password=&#x3C;PASSWORD>,uid=&#x3C;UID>,iocharset=utf8 0 0
   </code></pre>

   &#x20;

   Where:

   * &#x20;`<NordName>` is the Nord name or the Meshnet IP of the host device.
   * &#x20;`<ShareName>` is the name of the network share you are trying to access
   * `</path/to/folder>` is the path to the mounting point from Step 4 of the [Prepare a mounting point](#prepare-a-mounting-point) section.
   * `<USERNAME>` and `<PASSWORD>` are the authentication details for accessing the shared folder.
   * `<UID>` is the user ID from Step 5 of the [Prepare a mounting point](#prepare-a-mounting-point) section.

     &#x20;\
     **Example**

     <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">//secret.meerkat-pyrenees.nord/MeshnetFolder /home/meshnet/SharedFolder cifs username=meshnet,password=securepwd123,uid=1000,iocharset=utf8 0 0
     </code></pre>

     &#x20;
3. Press **Ctrl** + **X**, **Y**, and **Enter** to save changes and exit.
4. Run the following command to mount the network share:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo mount -a
   </code></pre>

   &#x20;
5. Apply the changes to your file system table by reloading SystemD with the following command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo systemctl daemon-reload
   </code></pre>

You can now access the shared folder from the sidebar in the **Files** app.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FUKjzSva0d7F0ItaIXZ2d%2Flinux_smb_mounted_dark.png?alt=media&#x26;token=a7e8f2c6-fd9d-448c-b911-a5efa6c37438" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FVx0QTRSgMRiemyvwS4KI%2Flinux_smb_mounted.png?alt=media&#x26;token=959959fd-26a7-49a8-a22b-dd4ed1e5e3bf" alt="The mounted shared folder highlighted in the &#x22;Files&#x22; app." width="417"></picture><figcaption></figcaption></figure></div>

## See also

* [Configure and access shared folders on Windows](https://meshnet.nordvpn.com/how-to/remote-files-media-access/set-up-folder-sharing/configure-and-access-shared-folders-on-windows)
* [Configure and access shared folders on macOS](https://meshnet.nordvpn.com/how-to/remote-files-media-access/set-up-folder-sharing/configure-and-access-shared-folders-on-macos)
