Restructure the Samba tutorial with steps components

This commit is contained in:
Djeex
2026-08-30 23:33:59 +02:00
parent 21a5eb670e
commit 588139bfa7
2 changed files with 110 additions and 99 deletions
+48 -41
View File
@@ -12,22 +12,23 @@ There are many tutorials for setting up Samba on Windows or on NAS systems like
![samba](/img/global/smb.svg)
## Sharing a Network Folder
## Create and configure a Shared Network Folder
::note
In this example, we will share the `/video` folder from a remote machine called `remote-machine`. We will access this folder from a machine called `local-machine`. The user connecting to the network drive will be `sambauser`.
::
::steps{level="3"}
### Install Samba Server
```sh
```bash [Terminal]
sudo apt update && sudo apt upgrade
sudo apt install samba smbclient cifs-utils
```
### Create the `/video` Folder
```sh
```bash [Terminal]
sudo mkdir /video
```
@@ -35,14 +36,14 @@ sudo mkdir /video
Now, edit the file `/etc/samba/smb.conf`.
::tip
__Tip:__ You can use [File Browser](/serveex/files/file-browser) to navigate and edit your files instead of using terminal commands.
::
```sh
```bash [Terminal]
sudo nano /etc/samba/smb.conf
```
::tip{icon=""}
✨ __Tip:__ You can use [File Browser](/serveex/files/file-browser) to navigate and edit your files instead of using terminal commands.
::
Find the `workgroup` variable and name your workgroup (e.g., `workgroup = WORKGROUP`).
Then scroll to the end of the file and add the following configuration:
@@ -60,66 +61,65 @@ Then scroll to the end of the file and add the following configuration:
```
Press :kbd{value="Ctrl+O"}, then :kbd{value="Enter"} to save, and :kbd{value="Ctrl+X"} to exit.
### Done !
::
### Create a Samba User and Group
Since we're using a secured share, we need to create a user and group to access it remotely.
Create the group:
::steps{level="3"}
### Create the group
```sh
```bash [Terminal]
sudo groupadd smbshare
```
Give the group control over the `/video` folder:
```sh
```bash [Terminal]
sudo chgrp -R smbshare /video
```
Set inherited permissions:
```sh
```bash [Terminal]
sudo chmod 2775 /video
```
### Create the user
Now add a no-login user — this user cannot log into the server but can access Samba.
```sh
```bash [Terminal]
sudo useradd -M -s /sbin/nologin sambauser
```
Add the user to the `smbshare` group:
```sh
```bash [Terminal]
sudo usermod -aG smbshare sambauser
```
Set a Samba password:
```sh
```bash [Terminal]
sudo smbpasswd -a sambauser
```
Enable the Samba account:
### Enable the Samba account
```sh
```bash [Terminal]
sudo smbpasswd -e sambauser
```
```sh
sudo ufw allow from remote-ip to any app Samba
```
### Done !
::
## Accessing a Shared Folder
---
\::
::steps{level="3"}
### Install Required Packages
```sh
```bash [Terminal]
sudo apt update && sudo apt upgrade
sudo apt install cifs-utils
```
@@ -128,7 +128,7 @@ sudo apt install cifs-utils
We will create a folder on our local machine where the remote `/video` folder will be mounted — e.g., `/mnt/video`.
```sh
```bash [Terminal]
sudo mkdir /mnt/video
```
@@ -138,7 +138,7 @@ To avoid typing our username and password every time, create a `.credentials` fi
Create it in the `/smb` folder:
```sh
```bash [Terminal]
sudo mkdir /smb
sudo nano /smb/.credentials
```
@@ -157,15 +157,20 @@ Press :kbd{value="Ctrl+O"}, then :kbd{value="Enter"} to save, and :kbd{value="Ct
Set proper file permissions:
```sh
```bash [Terminal]
sudo chmod 600 /smb/.credentials
```
### Mount the Shared Folder
::warning
__Warning:__ If you're using ufw as firewall, you need to add a rule to allow your remote server to access to your share.
```bash [Terminal]
sudo ufw allow from <your-remote-ip> to any app Samba
```
::
Now mount the folder:
```sh
```bash [Terminal]
sudo mount -t cifs -o credentials=/smb/.credentials //remote-ip/video /mnt/video
```
@@ -173,7 +178,7 @@ Replace `remote-ip` with your `remote-machine`'s IP address.
Verify the mount:
```sh
```bash [Terminal]
sudo mount -t cifs
```
@@ -181,38 +186,40 @@ Youll see details confirming the mount is successful.
Now you can access the `/video` folder of the `remote-machine` from your `local-machine`!
### Auto-mount on Boot
### (Optional) Auto-mount on Boot
By default, shares aren't auto-mounted after reboot. To automate this, edit the `/etc/fstab` file.
First, back it up:
```sh
```bash [Terminal]
sudo cp /etc/fstab /etc/fstab.bak
```
Then add the mount configuration line:
```sh
```bash [Terminal]
sudo echo //remote-ip/video /mnt/video cifs _netdev,nofail,credentials=/smb/.credentials,x-systemd.automount,x-systemd.device-timeout=15 0 0 >> /etc/fstab
```
Reboot the machine:
```sh
```bash [Terminal]
sudo reboot
```
After rebooting, verify the mount:
```sh
```bash [Terminal]
sudo mount -t cifs
```
### And done!
::
And done!
::tip
__Unmount the Shared Folder__
### Unmount the Shared Folder
```sh
```bash [Terminal]
sudo umount -t cifs /mnt/video
```
::