Share Files on Ubuntu 16.04 LTS with Windows 10 Systems

If you need to get Windows systems to access Ubuntu file and folder resources… you may need to use Samba… One can use other methods.. but Samba is the easiest to setup and works great with Windows machines…

Samba is an open source software that provides seamless file and print services to SMB/CIFS clients. Since Windows uses CIFS services, Samba can be a great tool to enable file and print sharing between Windows and Linux systems.

For this tutorial to work, you may want to set both Windows and Ubuntu machines on the same subnet. Our subnet for this post is going to be 192.168.1.0/24

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: Find Windows Workgroup name

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… Mostly, it would be called WORKGROUP

windows computer workgroup

Step 2: Add Ubuntu machine IP to Windows local 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

notepad C:\\Windows\System32\drivers\etc\hosts

Then add the local entry for the Ubuntu machine to be referenced by the named ubuntu16.04

192.168.1.3               ubuntu1610.localhost        ubuntu1016

Save your changes and you’re done.

STEP 3: ENABLE WINDOWS FILESHARING

To make fileshare possible, it must be enabled on the systems that are sharing. To enable file sharing on Windows, 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 16.10

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.

sudo apt-get install samba samba-common python-glade2 system-config-samba

After installing Samba, go and config Samba.

Step 5: Configure Samba Public share

Now that Samba is installed, run the commands below to backup its default configuration file.

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

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…

#============================ Global definition ================================
 
[global]
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 ============================== 

[Public]
   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

Now that Samba is configured and the share folder block is added, go and create the folder you want to share. To do that, run the commands below.

sudo mkdir -p /samba/public

Set the permissions so that everyone can read and write to it.

sudo chown -R nobody:nogroup /samba/public
sudo chmod -R 0775 /samba/public

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…

ubuntu samba sharing

 

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 adduser richard smbgroup

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.

cd /samba/
sudo chown -R root:smbgroup protected
sudo chmod -R 0770 protected

When you’re done creating the protected share, go and share it in the smb.conf file.

sudo nano /etc/samba/smb.conf

Then add configuration block below into smb.conf file just below the one above

[Protected]
  path = /samba/protected
  valid users = @smbgroup
  guest ok = no
  writable = yes
  browsable = yes

Save your changes and you’re done.

Restart Samba and test your changes.

sudo service smbd restart

You should now see two folders… one is protected

ubuntu sharing windows 10

 

Many more shares can be defined using the format above.

Only member of the smbgroup will be able to access the Protected area…

You could map the drive in Windows for easy access….

ubuntu samba shares

Enjoy!

ubuntu samba windows

That’s it! This is how to setup Samba to share files with Ubuntu

You may also like the post below:

Upgrade WordPress via SSH on Ubuntu 16.04 LTS

 

3 Replies to “Share Files on Ubuntu 16.04 LTS with Windows 10 Systems

  1. $ sudo apt-get install samba samba-common python-glade2 system-config-samba
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package python-glade2 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package samba-common is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package samba is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    samba-libs libnss-winbind libpam-winbind

    E: Package ‘samba’ has no installation candidate
    E: Package ‘samba-common’ has no installation candidate
    E: Package ‘python-glade2’ has no installation candidate

  2. when I try to log onto the protected folder on windows I get an error message
    \\UBUNTU\Protected is not accessible. You might not have permission to use this network resource.

    Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.

  3. I think Ubuntu 16.04 is the MS equivalent of Vista. A total POS.
    I’ve tried to share out a drive on this machine and I’ve done ten different methods and I always get the same error. It’s garbage.
    BTW! The instructions here? Don’t waste your time – I did and I’m sorry for the minutes I’ve lost trying it.
    Garbage!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.