SMB

In this tutorial, i'll use ubntu as my samba client and windows as the smb sahre server

SMB SERVER

This is the list of needed ports to be open by the firewall to let smb do the work properly:

sudo apt install samba

sudo ufw allow port 137/udp comment "NetBIOS Name Service"
sudo ufw allow port 138/udp comment "NetBIOS Datagram Service"
sudo ufw allow port 139/tcp comment "SMV Over NetBIOS (Pre-Windows 2000)"
sudo ufw allow port 445/tcp comment "SMV Over TCP (Pre-Windows 2000 AND newer)"

in the /etc/samba/smb.conf add the following lines:

[touk_home_directory]
        comment = touk's hme directory
        path = /home/touk
        read only = no
        browseable = yes
        valid users = touk

sudo smbpasswd

and provide the user’s password

sudo systemctl restart smbd

Now on my windows machine i should access the shared folder

Samba Client

NOTE: PLEASE READ RED NOTES

In this scenario, i am trying to connect my Ubuntu machine to my Samba share folder (Windows folder )

The Samba protocol (SMB/CIFS) is used for file and printer sharing across a network. It is commonly associated with Windows file sharing, but it is also implemented by Samba, an open-source software that provides SMB/CIFS services on non-Windows platforms like Linux and macOS.

So, the server you are connecting to could be a Windows server, a Linux server running Samba, or any other device that implements the SMB/CIFS protocol.

  1. Install the cifs-utils package if it is not already installed:

sudo apt-get update
sudo apt-get install cifs-utils
  1. Create a directory where you want to mount the Samba share. For example:

sudo mkdir /mnt/samba-share

  1. Connect to the shared folder via SMB mount

sudo mount -t cifs -o username=ADMIN,noperm //192.168.1.100/D /mnt/smb_share

noperm: i am telling the linux kernel to ignore permissions, and let samba do the job. If you leave that off you will be connected read only regardless of the share permissions

You will be prompted to enter the password

touk@ubuntu:~$ df -h
Filesystem         Size  Used Avail Use% Mounted on
udev               3.4G     0  3.4G   0% /dev
tmpfs              686M  2.2M  684M   1% /run
/dev/sda5           39G   34G  2.7G  93% /
tmpfs              3.4G     0  3.4G   0% /sys/fs/cgroup
/dev/loop0         128K  128K     0 100% /snap/bare/5
/dev/loop1          56M   56M     0 100% /snap/core18/2785
/dev/loop2          56M   56M     0 100% /snap/core18/2790
/dev/sda1          511M  4.0K  511M   1% /boot/efi
//192.168.1.100/D  156G  127G   30G  82% /mnt/smb_shar

root@ubuntu:/mnt/smb_share# touch smb_shard.txt

We can perform a persistent mount by editing the /etc/fstab

The kernel needs to read the credentials when booting but we don’t want to store our credentials in plain text, for that we will create a hidden folder

touch .smbcredentials (You can call it what you want)

vim .smbcredentials

Inside that folder you can pass your username and password:

user=ADMIN

password=p@ssw0rd

before I mount, I need to change ownership for the mounting point, because when the system boots up, the user is being used is root

sudo chown touk:touk /mnt/smb_sahre

And now:

vim /etc/fsatb

Inside fstab i use ip address because i don’t know if dns has been loaded or not

//192.168.1.10/D   /mnt/smb_share   cifs   credentials=/home/touk/.smbcredentials.uid=1000,gid=1000,noperm   0  0

Notice that i am not using tild ‘~’, because when at boot time, root is the one being used by kernel

NOTE!!: last 2 options, make sure to use 0. For file system check at boot, if it is set to 1 and your system can not connect to the server, YOUR SYSTEM WILL FAIL TO BOOT!

Last updated