Several methods are possible to set up a network share in Ubuntu (and its official variants Xubuntu, Kubuntu, Lubuntu, ...) in order to easily exchange files with other computers on the same network. Here we will see how to do it with the Samba protocol.
Introduction
Several protocols allow you to share folders on a local network. The two main ones are:
SMB (Server Message Block): originally on Windows with the old name CIFS (Common Internet File System). Samba is its open-source version for Linux systems.
NFS (Network File System): initially intended for Unix systems (including Linux), but also available for Windows or Mac.
In this tutorial, we will be using Samba to create a network share in Linux Mint. Indeed, this protocol has several advantages:
most OS (hence Ubuntu) support access to shared resources through the latter.
Setting up a network share in Ubuntu via Samba is easy once the additional packages are installed.
Install Samba to create network shares in Ubuntu
As said before, to be a client of an SMB OR CIFS share (access it), in Ubuntu, there is nothing to install. But if you want to create a share on your machine and therefore make it a kind of server, you have to install the samba package.
To do this, open a terminal and run the following command:
sudo apt install samba
Ubuntu offers its installation through the graphical interface, if it is not on the system, when you activate a share:
as well as on recent versions of Kubuntu:
During installation, your user account is added to the sambashare group. To add other users who can share their personal folders on the network, add them with the following command:
sudo adduser username sambashare
adduser: command to add a user. But it also allows you to add a user to a defined group. Here sambashare.
username: replace with your username.
Then restart your computer.
Allow incoming connections for samba in Ubuntu's firewall
On Ubuntu, UFW (Uncomplicated Firewall) is the tool for configuring the Linux kernel firewall (Netfilter). But it also has a graphical interface: Gufw. However, it is not installed by default on Ubuntu and its variants.
To install Gufw, do:
sudo apt install gufw
By default, UFW is not active (Personal Folder Profile in Gufw). In this case, there is no need to add any rules to allow inbound connections to samba. They are all already ...
However, if UFW is active (for example, if you use the Desktop or Public profiles in Gufw), the firewall blocks incoming connections. You must therefore create / add rules to authorize them from your local network on the ports used by Samba:
137 in TCP and UDP (NetBIOS Name Service)
138 in UDP (NetBIOS Datagram Service)
139 in TCP (NetBIOS Session Service)
445 in TCP and UDP (Windows Shared Folder Services)
(optional) 135 in TCP and UDP (RPC Service Locator) for sharing with Windows machines older than VISTA.
Check the status of UFW
In a terminal, do:
sudo ufw status
And you will have as result: State: Inactive or State: Active
This can also be checked in Gufw:
Add a rule to the Ubuntu Firewall (and variants) with Gufw
Open the Firewall Configuration Tool (Gufw).
Then go to the Rules tab (1). And click + (2) to add a rule.
In the Add rule to firewall window:
go to the Advanced tab (1). Then complete the required information:
(2) Name of the rule for easier identification.
(3) Rule security policy (Allowed in this case)
(4) Connection direction for which it applies (Enter in this case)
(5) Protocols concerned
(6) Definition of the source. To restrict access only to your local network enter the IP address and the mask of the latter. For example, if your IP is 192.168.0.x and the mask is 255.255.255.0, then the network IP is 192.168.0.0 and the subnet mask in short format will be 24. For this field, no need to define any Harbor.
If you do not know the IP of your network, click the copy IP address icon icon. This will copy your computer's IP to the Source IP field. Then replace the last digit with 0 to get the IP of your network.
(7) Definition of the destination. Complete the Ports field with those to authorize.
And do Add. The window does not close. So you can add another rule directly. Repeat the operation for all affected ports. Finally, once all the rules have been added, click Close.
Add a rule to the Ubuntu Firewall (and variants) from the command line
The authorization of a connection is done in this way
sudo ufw allow | deny | reject | limit [proto PROTOCOL] [from ADDRESS [port PORT] [to ADDRESS [port PORT]] [comment 'COMMENT']
For example: to allow incoming connections for samba on a local network in 192.168.0.x, the rules to add would be:
sudo ufw allow from 192.168.0.0/24 to any port 137 comment 'NetBIOS Name Service'
sudo ufw allow proto udp from 192.168.0.0/24 to any port 138 comment 'NetBIOS Datagram Service'
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 139 comment 'NetBIOS Session Service'
sudo ufw allow from 192.168.0.0/24 to any port 445 comment 'Windows shared folder services'
And this optional rule:
sudo ufw allow from 192.168.0.0/24 to any port 135 comment 'RPC service locator'
Or, if you want to allow all connections to samba regardless of the originating network, you can do:
sudo ufw allow samba
And eventually :
sudo ufw allow 135
Finally, check that the rules are added with:
sudo ufw status
Create a network share in Ubuntu and its variants
Create a network share in Ubuntu or Ubuntu Budgie through the graphical interface
To create a network share in Ubuntu, go to the file browser and right click on the folder to share.
So in the menu choose Sharing options or Property then Share tab. This takes you to the sharing configuration window.
(1) Validate the option to share the folder and have access to the settings.
(2) Enter a name for the share.
(3) Description is optional
(4) Check this option if you want to give the right to create, modify and delete on this folder to all users who will connect. But be careful, checking this option will also modify the rights on the local folder if the folder does not already have these rights.
(5) Check this option if you allow users without an account to connect to this share (not recommended)
Once the configuration is complete, click on Create a share (6).
If option (4) is checked, you have a message to apply the new rights to the folder.
If only users with an account are authorized (option (5) not checked), you must set the samba password for authorized users. To do this, enter the following command in a terminal:
sudo smbpasswd -a user_account
user_account being to be replaced by the desired one. But it must exist on the system.
Then enter the user's password twice for it to be added.
Create a network share in Kubuntu using the graphical interface
To create a network share in Ubuntu, go to the file browser and right click on the folder to share. Then in the menu choose Property then Share tab (1). So, set up your sharing.
(2) Validate the option to share the folder and have access to the settings.
(3) Give the share a name
(4) Check this option if you allow users without an account to connect to this share (not recommended)
(5) Define the rights for users on this share
And, once the configuration is complete, click OK (6).
So, if needed, set the samba password for the affected users:
sudo smbpasswd -a user_account
user_account being to be replaced by the desired one. But it must exist on the system.
Create a network share from the command line
Some official variants (Xubuntu, Lubuntu and Ubuntu Mate) do not allow authoring through their network sharing interface. It will therefore be necessary to directly modify the configuration file /etc/samba/smb.conf to add network shares. But, don't worry, it's not very complicated ...
This method works for all versions of Ubuntu. But only administrators can add new network share ...
Start by saving the original file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
And to restore it, you just have to do the reverse operation:
sudo cp /etc/samba/smb.conf.bak /etc/samba/smb.conf
Then edit this file:
sudo nano /etc/samba/smb.conf
Use the ← ↑ → ↓ keys to move the cursor. Once the text is inserted, do Ctrl + O to save the modification and Ctrl + X to exit.
So add at the end:
[Name_of_Share]
comment = A comment
path = / home / username / Name_of_shared_folder
browsable = yes
read only = no
guest ok = no
[Name_du_Share]: Name that the shared folder will take on the network
comment: optional, for example a description of the share
path: the path to your folder to share (case sensitive)
browsable = [yes | no]: authorize or not the navigation in the network share
read only = [yes | no]: read-only network share or allow writing for authorized users
guest ok = [yes | no]: (optional) allows or not unauthenticated users (without username) to access the share. If not specified = no.
Then, restart the Samba service:
sudo service smbd restart
And set the password for samba users:
sudo smbpasswd -a user_account
user_account being to be replaced by the desired one. But it must exist on the system.
Also, if you authorize others than your user to create / modify / delete documents, you must give them rights on the folder:
chmod a + w
Access the share on the network
Addresses to personalize according to your configuration ...
under linux
smb: // machine_name / share_name
or
smb: // machine_IP / share_name
under Windows
\\ machine_name \ share_name
or
\\ machine_IP \ share_name

Commentaires
Enregistrer un commentaire