[Linux][Samba]: How to Share Files and Printers to Windows Machine on the Network
On moving from the Windows environment to the Linux, you might get to a point you wish to share files and printers through the network. Yes, we do that too, you can share files and printers from a Linux machine to a Windows machine using Samba.
Samba?
Samba is a free software re-implementation of the SMB/CIFS networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member. [Wikipedia]
Okay, what next?
Now you’ve known a little bit of Samba, lets dive in and I show you what it can do. 🙂 We are going to install Samba on our Linux machine.
CentOS/Fedora
$ sudo dnf install samba samba-client
Debian/Ubuntu
$ sudo apt install samba
Setting Up Samba
After a successful installation, setup files are located in our dear /etc/samba
directory, and the main configuration file we will modifying is the smb.conf
file. So why not make a backup? 😉 We simply create a backup by copying smb.conf
to smb.conf.bak
just in case we do something wrong.
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Now lets commence on editing the configuration file by editing /etc/samba/smb.conf
. In most Windows systems, the default workgroup is WORKGROUP
so we are going to make sure our Samba is set to WORKGROUP workgroup by setting
#You can find this under the [global] section workgroup = WORKGROUP
Lets share files
Let me say, I want to share my Videos to the network which is at /home/jajo/Videos/
, I am going to append these codes to bottom of smb.conf
file
[Videos] comment = My Videos path = /home/jajo/Videos read only = No browseable = Yes guest ok = Yes create mask = 0755
Let me explain these:
- comment: This is a short description of the path you are trying to share
- path: This is the path to the directory you wish to share
- read only: This determines if the files or directories are allowed to be writable or not. Values are either
yes
orno
- browseable: Is Windows Explorer allowed to browse through this directory?
- guest ok: Is this directory accessible without password?
- create mask: Default permission to be set when a new file in created
You can add other directories you wish to share. Then save the file.
Creating a Samba User
Before we proceed, we need to add our user to Samba users so to be able to access protected files and directories. Lets add my user, that is jajo
by running:
$ sudo smbpasswd -a jajo
Enter the new password. Enter again to confirm. This is the password you use to access protected files and directories on the network. I.E. if you have guest ok
to no
Get Samba Up and Running
We have done the simple configuration, let us get Samba up and running
Debian/Ubuntu
$ sudo systemctl restart smbd nmbd
CentOS/Fedora
$ sudo systemctl restart smb nmb
After a successful restart of the services, you should go to Network in your Windows Explorer to find your Linux system 🙂
Not seeing it yet?
There is one problem I face most times, it is the firewall. Allow ports for Samba shares
Debian/Ubuntu
$ sudo ufw allow samba
CentOS/Fedora
$ sudo firewall-cmd --add-service samba
Everything should be running fine now. 🙂 And yes, this is not Windows, there is a way to monitor what is going on in your Linux on the network, just run
$ sudo smbstatus
Thank me later! 🙂