Freebsd Connecting to Windows Network Folders With Samba

Do you have many devices in the office, company, home, school or other? How do you transfer data between computers? How do you transfer data between computers? Do you use a flash drive or SD card to transfer data between computers? This question arises when you work with many computers in one place.

Samba is the answer, with Samba all your work can be completed easily on one network. You don't need to waste precious time when transferring files, documents and other large items quickly and easily, over a local network. This is a one-time setup, and then with a few mouse clicks you can share files between computers.

If you usually work with Windows and want to share files or documents over a local network, or you just want files or documents to be accessible by all computers, FreeBSD and Samba are the right choices. You can use the FreeBSD server as a gateway so that files or documents can be accessed by many computers.

The image below explains the process of connecting files or documents between FreeBSD (samba) and Windows.

Every user who wants to access files or documents must log in and depend on the access rights obtained. Users who successfully log in can read, create or modify files from the computer where they work.

Accessing the Samba server can also be done without a password, so everyone can access it. Although it is not recommended, some people really need it. For example, if you need to open access very quickly and you don't have time to set up limited access. It is highly recommended that each user use a password to log in, this is to protect data or documents from being opened by anyone.

1. Samba Server Specifications

OS: FreeBSD 13.2
Hostname: ns3
IP Address:
interfaces = nfe0
Samba Version: samba416
Python Version: python39
Dependencies: p5-Parse-Yapp, libiconv, curl, py-wsdd

2. Installation Preparation

Before we start installing Samba, we must first install the dependencies that Samba requires. The goal is for the Samba server to run normally. There are several dependencies that you have to install, but the most important ones are Python39, p5-Parse-Yapp, libiconv, py-wsdd. Other dependencies are usually installed automatically.
root@ns3:~ # pkg install python39 p5-Parse-Yapp libiconv net/py-wsdd
Once the above dependencies are installed, continue with installing Samba. In this article we will use the ports system to install Samba.
root@ns3:~ # cd /usr/ports/net/samba416
root@ns3:/usr/ports/net/samba416 # make config
When you run the "make config" command the Samba options menu will appear. You should mark the option "PYTHON3". Look at the image below.

Continue with the command "make install clean".
root@ns3:/usr/ports/net/samba416 # make install clean
Create a Start Up script rc.d, so that the Samba server can run automatically. Open the "/etc/rc.conf" file and type the script below into the "/etc/rc.conf" file.


At the end of the installation, the net/samba416 port does not include the "smb4.conf" configuration file required to get Samba up and running, so we will create a "smb4.conf" file. To make it easier to script the /m file, we will create a two-part script.
1. Global Settings
2.Share Definitions.

Below is an example of the complete script "/usr/local/etc/smb4.conf". Adjust to the specifications of your Samba server computer.

#======================= Global Settings =====================================

workgroup = WORKGROUP
server string = FreeBSD %v (%h)
server role = standalone server
hosts allow = 192.168.5. 127.
;  guest account = pcguest
log file = /usr/local/samba/var/log.%m
log level = 1
max log size = 50
;  realm = MY_REALM
passdb backend = tdbsam
bind interfaces only = yes
#interfaces = nfe0 lo0
interfaces =
wins support = no
wins server =
local master = yes
preferred master = yes

#============================ Share Definitions ==============================
   comment = Home Folder
   browseable = yes
   writeable = yes
   valid users = %U
   create mode = 0644
   directory mode = 0755
   path = /usr/local/etc/sambashare/personal
   guest ok = no

   comment = Public Folder
   path = /usr/local/etc/sambashare/public
   browseable = yes
   writeable = yes
   guest ok = no
   create mode = 0664
   directory mode = 0775
   valid users = %U

   comment = Shared Folder
   path = /usr/local/etc/sambashare/shared
   browseable = yes
   writeable = yes
   guest ok = no
   create mode = 0666
   directory mode = 0777
   valid users = %U

   comment = Guest Folder
   path = /usr/local/etc/sambashare/guest
   browseable = yes
   writeable = yes
   guest ok = no
   create mode = 0666
   directory mode = 0777
   valid users = %U

3. Configuration Preparation

This process is an inseparable part of the installation process. The first step we have to do after having the configuration file "smb4.conf" is to create a directory.
root@ns3:~ # mkdir -p /usr/local/etc/sambashare/personal
root@ns3:~ # mkdir -p /usr/local/etc/sambashare/public
root@ns3:~ # mkdir -p /usr/local/etc/sambashare/shared
root@ns3:~ # mkdir -p /usr/local/etc/sambashare/guest
After that, run the "chmod" command, this command is used to grant access rights/permissions to the owner, normal users and non-users. We follow the script from the "smb4.conf" file.
root@ns3:~ # chmod 775 /usr/local/etc/sambashare/personal
root@ns3:~ # chmod 775 /usr/local/etc/sambashare/public
root@ns3:~ # chmod 777 /usr/local/etc/sambashare/shared
root@ns3:~ # chmod 777 /usr/local/etc/sambashare/guest
The next step is to edit the "/boot/loader.conf" file, and enter the script below.


To secure the data or documents that are shared, we create a user and password. With a user and password, not everyone can access the file or document.
root@ns3:~ # pw add group samba
root@ns3:~ # pw add group freebsd
The script above is used to create a group named "samba". After you create a group, continue with creating users. In this example we will create 3 users, John, Mary and Peter who are in the Samba group
root@ns3:~ # pw add user -n john -g samba -s /sbin/nologin -c "samba john"
root@ns3:~ # pw add user -n mary -g samba -s /sbin/nologin -c "samba mary"
root@ns3:~ # pw add user -n peter -g samba -s /sbin/nologin -c "samba peter"
root@ns3:~ # pw add user -n jackson -g freebsd -s /sbin/nologin -c "samba guest"
Give a password to each user.
root@ns3:~ # pdbedit -a -u john -f "john chaplin"
root@ns3:~ # pdbedit -a -u mary -f "mary rose"
root@ns3:~ # pdbedit -a -u peter -f "peter joe"
root@ns3:~ # pdbedit -a -u jackson -f "jackson samba"
To make it easier for you, look at the image below.

Are you confused? Now, we continue with the chown command. This command is used to change the ownership of a file or directory.
root@ns3:~ # chown -R john:samba /usr/local/etc/sambashare/shared
root@ns3:~ # chown -R mary:samba /usr/local/etc/sambashare/public
root@ns3:~ # chown -R peter:samba /usr/local/etc/sambashare/personal
root@ns3:~ # chown -R jackson:freebsd /usr/local/etc/sambashare/guest
Run the samba server.
root@ns3:~ # service samba_server restart

4. Windows Configuration

In this step we will start configuration in the Windows system environment. Open "C:\Windows\System32\drivers\etc", after that you enter the script below.    ns3

In the Samba application that we are studying, FreeBSD is the Samba server and Windows is the Samba client. So all files or documents that you want to share must be placed on the FreeBSD server. Any user who wants to use these files or documents can only access them through Windows. In large environments such as schools, hospitals or companies, a network administrator is needed to manage access rights to files or documents that are shared or can be accessed by users.

You copy all files or documents to the FreeBSD server according to user access rights. After that run "chmod", as in the example below.
root@ns3:~ # chmod 644 /usr/local/etc/sambashare/shared/*
root@ns3:~ # chmod 644 /usr/local/etc/sambashare/public/*
root@ns3:~ # chmod 666 /usr/local/etc/sambashare/personal/*
root@ns3:~ # chmod 666 /usr/local/etc/sambashare/guest/*
Run the command above, every time a file or document is added to the FreeBSD server.

Every user who wants to access a file or document can run it through Windows Explorer". OK, let's just start trying the Samba application on the Windows client. Open Windows Explorer and type "\\\personal" or "\\ns3\ personal".

To delete the connection to the Samba server on Windows, run "cmd", and type the command "net use * /delete".

You can also try the command below in "cmd" shell.
C:\Users\blogspot>net use \delete \\\personal
C:\Users\blogspot>net use \delete \\\public
C:\Users\blogspot>net use \delete \\ns3
The functions and uses of Samba are numerous. So you have to try a lot on your FreeBSD server and also read a lot of Samba tutorial articles on the Google search engine. The discussion in this article is only part of learning Samba. However, the installation and configuration process is almost the same if you want to combine it with a DHCP or DNS Bind server.
    Iwan Setiawan

    I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

    Post a Comment

    Previous Post Next Post