What is Samba
What is Samba
Samba is standard Window interoperability (Able to exchange and communication information) with Unix-like system.
Samba provides file services through
- CIFS (Common Internet File System): This is obsolete dialect of the SMB protocol
- SMB (Server Message Block): More recent and up to date
Both are Window's file sharing protocol for storage system like network-attached system. This basically means that you can run a NAS on Unix like system and by using Samba, Window OS can also access the NAS through Samba.
Samba File Server
You can configure a Samba File Server to enable file sharing across different operating system over network, hence network attached storage. To set up a Samba File Server on Ubuntu follow the guide below:
1. Install Samba
sudo apt update
sudo apt install samba
2. Create a sample directory to share
This directory can be a storage that's mounted through different drive that have Raid set up, it doesn't matter, ultimately at the end of the day, you will just be sharing a directory to those that want to access the files.
mkdir /data
Let's say we want to share the /data
file that we have just created, after getting Samba file server installed and ensuring that it is up and running through sudo systemctl status smbd
we will need to configure the samba file server to serve this particular directory.
3. Editing samba config file to share the directory
This can be done by editing /etc/samba/smb.conf
file and appending at the end of the file
[sambashare]
comment = Samba on Ubuntu
path = /data
read only = no
browsable = yes
- Line 1 denotes the name of the folder that we are sharing, this name is important as this is how other operating system will use to find the folder that you have shared
- Line 2 denotes just a simple comment about the share
- Line 3 denotes the path to the directory of the share
- Line 4 denotes that the share folder can be modified. If you want to only make the file readable, then you will have to toggle it to
yes
- Line 5 denotes that file managers in Ubuntu / Window's file explorer in Window can find the share under Network
Finally, after you make the change you will need to restart the samba file server through
sudo service smbd restart
4. Adding user to access the file
Because Samba doesn't use the system account password (whatever username and password that you have set up for Ubuntu), you will need to setup a separate password for the user account which the other host that want to access the file need to use in order to access the files.
Even though it doesn't use the system account, the account that you will be creating with samba will need to exist, otherwise it will not save
sudo smbpasswd -a <username>
Running the command above will prompt you entering a password for the username that you have provided
You can also find the list of users that you have created by running
sudo pdbedit -L -v
5. Connecting to share
Now in order to see the file directory that is shared through Samba, on Ubuntu you can open up a default file manager and click Connect to Server then enter in:
smb://ip-address/sambashare
This is the same for macOS
On Windows you will have to open up file manager and edit the file path to simply
\\ip-address\sambashare
You will be prompted to enter in the username and the password that you have created.
Restricting file access
To restrict a file access in Samba to only a set of users that you have specified that you configure you smb.conf
as such:
[special]
path = /home/special
read only = no
writeable = yes
browseable = yes
valid users = user1, user2, user3
No Comments