Search
K
Links

Configure and access shared folders on Linux

Learn how to configure shared folders and access them on Linux over Meshnet.
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.
Note
For this procedure, Ubuntu 22.04.1 LTS is used as an example.

Prerequisites

Before you begin, you need to download and prepare the Samba app on your Linux device. Samba uses the SMB protocol to allow the sharing of resources over the network.
Install Samba
To install Samba, on your system:
  1. 1.
    Open Terminal.
  2. 2.
    Run the following command, which will fetch updates from your repositories and install Samba:
    sudo apt update && sudo apt install samba -y
Enable Samba authentication
To secure access to your shared folders, you need to create a Samba password.
  1. 1.
    Open Terminal.
  2. 2.
    Run the following command, which will prompt you to create a new Samba password for your current user:
    sudo smbpasswd -a $USER
  3. 3.
    Enter and confirm your new password.
    Terminal output asking for the SMB password.
  4. 4.
    Restart the Samba process with this command:
    sudo systemctl restart smbd

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.
GUI
Terminal
To create a network share using a file manager's network-sharing options:
  1. 1.
    Right-click the folder you want to share and select Properties.
  2. 2.
    Switch to the Local network share tab.
  3. 3.
    Select Share this folder, and, if needed, enter a custom name for your network share.
  4. 4.
    Click Create share.
Take the following steps to share a folder via the command line:
  1. 1.
    Open Terminal.
  2. 2.
    Navigate to the folder that you want to share and print out its absolute path by using the pwd command.
    Example
    /home/meshnet/Desktop/MeshnetFolder
    Output of 'pwd' command
  3. 3.
    Run the following command to open the Samba configuration file using the Nano text editor:
    sudo nano /etc/samba/smb.conf
  4. 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:
    [<ShareName>]
    path = </path/to/folder>
    read only = no
    browsable = yes
    Example
    Samba configuration file with the changes for the shared folder.
  5. 5.
    Press Ctrl + X, Y, and Enter to save changes and exit.
  6. 6.
    Run the following command to restart the Samba process:
    sudo systemctl restart smbd
Note
To access the shared folder, the peer device will need to use your Linux username and the previously created Samba password for authentication.

Access shared folders

Note
You can find platform-specific instructions for accessing the shared folder in the appropriate guides:
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. 1.
    Run the nordvpn meshnet peer list command and copy the Nord name of the sharer's device.
    Terminal output of the 'nordvpn meshnet peer list' command with a peer device's Nord name underlined.
  2. 2.
    Open GNOME Files and select Other locations in the sidebar.
    "Other locations" option highlighted.
  3. 3.
    In the Connect to server field, enter smb://, paste the Nord name, add a slash (/) followed by the network share name, and click Connect. Example
    smb://secret.meerkat-pyrenees.nord/MeshnetFolder
    Shared folder's network path entered in the file manager.
  4. 4.
    Select Registered user and enter the username and password for accessing the shared folder.
  5. 5.
    Click Connect.
The shared folder should open in your file manager.

Mount a shared folder

The shared folder you connect to becomes unavailable after a system restart, which means that each time you wish to access the files stored in the folder, you would need to reconnect to it. However, by utilizing CIFS, you can mount the shared folder directly on your system and use it as a persistent storage location.

Prepare a mounting point

  1. 1.
    Open Terminal.
  2. 2.
    Fetch repository updates and install CIFS by entering the following:
    sudo apt update && sudo apt install cifs-utils -y
  3. 3.
    Create a new directory using the mkdir command, where you want to mount the shared folder. Example
    mkdir SharedFolder
  4. 4.
    Navigate to the newly created folder using the cd command and print out its full path using the pwd command.
    Ouput of 'pwd' command
  5. 5.
    Check your user ID number by executing this command:
    echo $UID

Edit the file system table

  1. 1.
    Open the fstab file with root privileges using the Nano text editor by running this command:
    sudo nano /etc/fstab
  2. 2.
    At the end of the file, append the following line for the shared folder:
    //<NordName>/<ShareName> </path/to/folder> cifs username=<USERNAME>,password=<PASSWORD>,uid=<UID>,iocharset=utf8 0 0
    Where:
    • <NordName> is the Nord name or the Meshnet IP of the host device.
    • <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 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 section.
      Example
      //secret.meerkat-pyrenees.nord/MeshnetFolder /home/meshnet/SharedFolder cifs username=meshnet,password=securepwd123,uid=1000,iocharset=utf8 0 0
  3. 3.
    Press Ctrl + X, Y, and Enter to save changes and exit.
  4. 4.
    Run the following command to mount the network share:
    sudo mount -a

See also

© 2023 Nord Security. All Rights Reserved.