Samba is the most popular and efficient way with which you can share your files and directories between Linux, Windows and Mac. You just have to create a Samba user, Decide which file/directory you wish to share and Set the permissions, in order to create a Samba share. Well, initially, this might seem to be difficult- especially for beginners, but when you understand all the configuration options, it will seem to be as simple as anything.
This tutorial will explain how to share files and directories on Linux with Windows and Mac clients.
Step 1: Installing SambaFor Red Hat Linux and derivatives, Samba can be installed using
For Debian and derivatives, you can use
$ yum install samba smbfs
apt-getas follows (Know more about
$ sudo apt-get install samba smbfs
Step 2 : Samba Configuration
The best part in samba is, there is a single configuration file -
/etc/samba/smb.conf. So, before making any configurations, it's always a better practice to have this file backed up, so that, if anything goes wrong, we can revert the changes back to original ones pretty easily.
Now that, we can move forward to edit this file. Let's do it.
$ cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
$ vi /etc/samba/smb.conf
When you open the
smb.conffile, you'll typically observe three sections here -
[printers]. Let's now see the significance of each of them:
[global]: As the name denotes, setting defined here will be common to all the subsequent sections.
[share]: Settings related to the shares are defined here.
[homes]: If this section is present and when a user tries to connect to
share_namewhich is not configured in
smb.conf, then it is assumed that
share_nameis a Linux user and it is trying to connect to his home directory.
[printers]: Settings for shared printers appear here.
[global] workgroup =
userpassdb backend = tdbsam cups options = raw load printers = yes log file = /var/log/samba.log.%m [homes] comment = Home Directories browseable = no writable = yes [share_name] comment =
no... SOME MORE PERMISSIONS HERE ... [printers] comment = All Printers path = /var/spool/samba guest ok = no printable = yes browseable = no
Above is just an example of
/etc/samba/smb.confconfiguration. It might vary from system-to-system, but the syntax would be the same. The values in the colored format can be adjusted to meet your requirements. Let's now understand the configuration part in more detail:
security: Here, we will specify the mode of authentication Samba should use to authenticate a user. It can be any of the following:
user: It needs to create a Samba user and this samba user must also be the Linux user.
domain: A user account present in a centralized account repository shared between domain controllers.
ads: Active directory security mode.
writable: To set Write permission for the share.
read only: To set Read only permission for the share.
browsable: To set browsing permissions for the share.
read list: Users to be given read only permissions to the share.
write list: Users to be given write permissions to the share.
valid users: Users allowed to access the share.
invalid users: Users to be prevented from accessing the shares.
hosts allow: IP addresses allowed to access the share.
create mask: Permissions to be given when users create anything inside the share.
Step 3. Creating a Samba User
The most important thing to be remembered is - A Samba user must also be the actual system user. So, in order to create a new Samba user, you must ensure that, that user must be a system user. If it is not, then add that user to the system first.
So, in case the user is the system user and we wish to create a samba user, use the
smbpasswdcommand as follows:
You will be asked for a Samba Password, when you're done, it will create a Samba user for you.
$ smbpasswd -a USERNAME
Here, I need to create a share with name
myshareand it must be accessed by the user
mandaronly. For that, I must create a system user first.
Then, I must create a Samba user.
$ useradd mandar $ passwd mandar
Time to make some configurations.
$ smbpasswd -a mandar
When we make any configuration changes, we must restart the services.
$ vi /etc/samba/smb.conf [global] ... ... ... [myshare] comment = This is Mandar's Share path = /smbshare/mandar valid users = mandar hosts allow = 192.168.100.3 writable = yes public = no [printers] ... ...
And we're done. If we try to access this share from the system 192.168.100.3 with the user
$ /etc/init.d/smb restart OR $ service smb restart
mandar, it should work. In order to access this share from my windows machine, I would execute in the 'RUN' box -