Custom CMS Tutorial

LAN share folder

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