file sharing on your home network with Samba
I have several machines at home and an old laptop is connected to our TV with a VGA cable. When I download something on my main machine and I want to watch it, I need to copy it on a USB or an external HDD to take it over to the old laptop. A few days ago I came up with the idea to use file sharing at home. My main machine is almost always switched on, so it could be the file server, and my old laptop connected to the TV would be the client.
There are several solutions for this, e.g. NFS and Samba, just to mention the most well-known ones. First I tried NFS but I ran into some problems. First, I had to create one subnet at home. When I had two, the machines in different subnets couldn’t ping each other (refer to this post to see how to create one subnet with two routers). Once I had one subnet, I couldn’t always make NFS work. Sometimes it worked, sometimes it didn’t. And very often I got “permission denied” error when I wanted to connect to the server.
I talked to a friend of mine about it, Todi, and he suggested that I should try Samba instead. I did and it worked like a charm :) So here I sum up the steps for sharing directories at home with Samba between two Linux machines. Samba also works with other operating systems (Windows, Mac), but I will try that later.
I used the excellent Arch wiki as a starting point. I tried this method on two Manjaro machines but Ubuntu should be the same.
This is the machine that contains files that you want to access on other machines. Install the “
samba” package and create the config file:
# cp /etc/samba/smb.conf.default /etc/samba/smb.conf
To provide basic file sharing, enable and start these services: “
smbd.service” and/or “
nmbd.service“. I’m not sure if “
nmbd.service” is needed.
I like to see my shared folders in one place. Create the “
/srv/samba” folder and mount here the folders you want to share. I added the following lines to my “
/mnt/ext1/movies /srv/samba/movies none bind 0 0 /mnt/ext1/torrent /srv/samba/torrent none bind 0 0 /mnt/ext1/tutorial /srv/samba/tutorial none bind 0 0
Of course, in the “
/srv/samba” folder I created three empty folders first (
When ready, run the command “
sudo mount -a” to mount these new folders. Verify if they are correctly mounted.
Now, it’s time to edit the
/etc/samba/smb.conf file. My global part looks like this:
[global] ... workgroup = MYGROUP hosts allow = 192.168.0. 127. ...
It means that all machines on my home network and my localhost can connect to the server. The abbreviations mean
The next thing is to create a share. Add these lines to the bottom of the config file:
[share] comment = Jabba's stuff path = /srv/samba available = yes valid users = jabba browsable = yes public = yes read only = no writable = yes create mask = 0777 directory mask = 0776
It means: the folder “/srv/samba” is served on the server (recursively); the client will need to authenticate itself (see later), and the client will have write permission too.
Note: I could set up Samba quickly but the client couldn’t do any modifications. The shared folder was read-only. The trick is to create a Samba user. On the server allow this user to connect, and on the client use the credentials of this user when connecting to the server. Let’s see how to do that.
On the server create a Samba user:
sudo smbpasswd -a
For the sake of simplicity here I chose the same username that is my account’s name on Linux. Provide a password for this user and add this user in the “valid users = …” line (as seen above).
After editing the config file, always run the command “testparm -s”, which checks for syntax errors. Restart the “smbd.service” and you are done with the server side.
Install the package “
smbclient“, that’s all you need. To see public shares on a server, run this command:
smbclient -L <server> -U%
I like to see my mounted Samba directories in one place, so I created the directory “/smb”:
# mkdir /smb
Then mount the shared folder of the server. Don’t forget to use the credentials of the Samba user that was created before:
#!/usr/bin/env bash sudo mount -t cifs //hq/share/ /smb/ -v -o username=jabba,password=***
hq” is the name of my server and “
share” is the name of my share that comes from the Samba config file (it’s under the section name “
[share]“, so this is its name). The username and password belong to the previously created Samba user.
If everything went well, then you should see the shared folders under “
/smb“. The shared folders are writable on the client side.
File manager configuration
If you want to access Samba shares from Thunar, Nautilus, etc., then install the package “
gvfs-smb“. Then in the location bar (CTRL+L jumps there) simply write “
smb://hq/share” (in this example). Provide the Samba username and password and you are good to go.
On my home network the speed of Samba is not very fast. From the server I can copy with a speed of 1.5 MB/sec. When NFS worked, its speed was 1.7 MB/sec. So NFS was a bit faster, but there is no big difference. And Samba was easier to configure. However, for watching movies on a client, this speed is enough.
The Windows client must be in the same workgroup with the server. As seen above in the “
[global]” part, the server is in the workgroup called “
MYGROUP“. Here is a help that explains how to join a workgroup. Here are some screenshots (sorry for the Hungarian version but that’s what I have at home). Click on the images to enlarge them:
After changing the workgroup’s name, you must restart the computer (yeah, it’s Windows). Then open the Explorer, go to the networks and you should see the Samba server. Connect with your credentials.
Install the package “
cifs-utils” and proceed as described above.