When you have both Windows and Ubuntu machines on the same network, you can use Samba + SMB/CIFS to enable files and printer sharing… This brief tutorial is going to show students and new users how to get that done..
Samba is an open source software that provides seamless file and print services to SMB/CIFS clients… Samba enables Linux systems, including Ubuntu to share files with Windows systems, including Windows 10…
For this tutorial to work, you may want to configure both the Windows and Ubuntu machines on the same subnet. This means they should be able to communicate over the network… For this tutorial, we’re going to be using a 192.168.1.0/24 network…
The Windows machine will have IP address 192.168.1.2 and the Linux machine 192.168.1.3
Both machine will also be in the same local workgroup. You can name the workgroup whatever you want, but for this post, our workgroup will be the default Windows workgroup called WORKGROUP
Windows IP address =========================> 192.168.1.2
Ubuntu IP address ==========================> 192.168.1.3
Workgroup Name ===========================> WORKGROUP
Both the Windows and Ubuntu machines will be member of the local workgroup called WORKGROUP
Step 1: Identify Windows Workgroup
To find out which Workgroup Windows machine belongs, open the command prompts and type the commands below
net config workstation
When you run the commands above, you should see your current Workstation domain name for the computer… usually called WORKGROUP
Step 2: Add Ubuntu Machine IP to Windows Host File.
If you don’t have a DNS system in place and you want to reference each system by their names, you’ll want to add their names in the local host file on each machine.. For Windows system, open the commands prompt as administrator and run the commands below
Then add the local entry for the Ubuntu machine to be referenced by the named ubuntu16.04
Save your changes and you’re done.
To add Windows system name to Ubuntu host file, press Ctrl — Alt –T on your keyboard to open the command terminal… then run the commands below:
sudo nano /etc/hosts
Then type the IP with hostname for Windows machine… and save the file..
STEP 3: ENABLE WINDOWS FILESHARING
To make file sharing possible, that feature must be enabled on Windows systems… To enable it, run the commands prompt as administrator and run the commands below
Then run the commands below to enable filesharing and network discovery.
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes
Step 4: Install Samba on Ubuntu
At this point, Windows and Ubuntu systems should be member of the same workgroup and both systems have entries in their local host file to reference the other by name.
Next, logon on to the Ubuntu machine to install Samba. To install Samba, run the commands below.
Next, open Samba configuration file by running the commands below.
sudo nano /etc/samba/smb.conf
Copy and paste the content below into the file and save… this will create a share named Public where everyone will have access on the Ubuntu to it…
#============================ Global definition ================================
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu1604
security = user
map to guest = bad user
name resolve order = bcast host
dns proxy = no
bind interfaces only = yes
#============================ Share Definitions ==============================
path = /samba/public
writable = yes
guest ok = yes
guest only = yes
read only = no
create mode = 0777
directory mode = 0777
force user = nobody
Save your change
Step 6: Create the Public folder to share
Next, create the public folder where everyone should have access to as defined in Samba configuration above…
sudo mkdir -p /samba/public
Set the permissions so that everyone can read and write to it.
Restart Samba and open Windows File Explorer to view the shared location on Ubuntu
sudo service smbd restart
Now go to your Windows machine and you should see the shared Public folder on Ubuntu from when you browse File Manager as shown below…
Everyone should have access there.
Step 6: Configure Samba Private Share
Now you know how to create Samba public shares, let’s go and create private and protected shares. Only users that are member of the approved group will be able to access the secure location with passwords.
First create a samba group called smbgroup for the share.. only members will have access. To create a groups in Ubuntu, run the commands below.
sudo addgroup smbgroup
Then add a user to the group by running the commands below
sudo usermod -aG smbgroup richard
Finally, all users who need to access a protected samba share will need to type a password. To add a user to samba password database, run the commands below for each user.
sudo smbpasswd -a richard
The user will be prompted to enter and confirm a password. This password will be used to access the protected samba shares.
Next, go and create a protected share in the /samba directory.
sudo mkdir -p /samba/protected
Then give only root and members group access to this share.