The easiest way to set up Samba for file-sharing

Samba is directly compatible with Windows and allows for a lot of configuration, but if you just want a stand-alone Samba server on your network, it's an easy setup. Vincent Danen shows you how.

Samba, Apache, and MySQL are probably the biggest open source projects found on Linux (aside from the Linux kernel itself, of course). All three have really elevated Linux for use in home networks and corporate environments.

With them, anyone can have a file and print server, a Web server, or a database. All three come with pretty much every Linux distribution you can find.

The most ubiquitous of the three is probably Samba, because it and the functionality it provides is found in every operating system. Linux, OS X, the BSDs and others use Samba. It is directly compatible with Windows because it uses the Windows file and print sharing protocols to allow for sharing Windows file systems on Linux and vice versa.

Samba allows for a lot of configuration, and there are many options to use -- primarily relating to authentication. When Samba 4 finally lands, it will be an incredible release with Active Directory support and being able to act as an Active Directory server, with internal LDAP and Kerberos servers to fully flesh out what is necessary for full integration with Windows networks. Until then, you can still hack Samba up to do a lot of these things, and it works fantastic as a client in Windows networks. You can make Samba work with Active Directory, with LDAP, and with local passwords.

Most people will just want a stand-alone Samba server somewhere on their network and that is the easiest to set up. To begin with, you need Samba installed on your system. This can be done by installing the "samba" or "samba3" (on some distributions) package, either using yum or apt-get or whatever mechanism your distribution uses to install packages. Once Samba is installed, edit the /etc/samba/smb.conf file. If you're using Red Hat Enterprise Linux or Fedora, you will need to make further changes if you have SELinux support enabled; the comments in smb.conf will help with the additional steps.

A very basic smb.conf file will look like this:

    workgroup = MYGROUP
    server string = Samba Server Version %v
    log file = /var/log/samba/log.%m
    max log size = 50
    security = user
    passdb = tdbsam
    comment = Home Directories
    browseable =no
    writable = yes

This is an absolutely basic configuration file. If you already have a workgroup defined, change the "workgroup" value to whatever you have already defined for the network. The rest can remain as-is. This will allow you the ability to connect to the server and mount your home directory on the server from any other machine on the network.

The next step is to create the local passwords. Because Samba does not use the authentication credentials of the system (i.e., via PAM), you need to add the user to the Samba user database:

# smbpasswd -a user

Provide the password for the user in question. Also note that this user must also exist on the system, so if this is a new user you must use useradd to create the user and passwd to set their password. If the user already exists on the server, there is no need to do anything more than set their Samba password.

Once this is all complete, start the Samba server (or restart it):

# service smb start

Now, from another system, you can use smbclient to list available shares:

% smbclient -L \\
Domain=[CERBERUS] OS=[Unix] Server=[Samba 3.5.4-62.fc13]
       Sharename       Type      Comment
       ---------       ----      -------
       IPC$            IPC       IPC Service (Samba Server Version 3.5.4-62.fc13)
       user            Disk      Home Directories
Domain=[CERBERUS] OS=[Unix] Server=[Samba 3.5.4-62.fc13]
       Server               Comment
       ---------            -------
       Workgroup            Master
       ---------            -------

To mount the share, connect to \\\user using the network browser in GNOME, the Finder in OS X, or Windows Explorer in Windows.

This is the easiest way to set up Samba for file sharing. Other mechanisms exist for sharing files on a LAN, such as NFS or SSHFS, but Samba is quick, easy to set up, and reliable. It is also cross-platform, making it easy to share files amongst various operating systems.

Get the PDF version of this tip here.


Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.


Linux, an old veteran, Windows is a widow, nothing more ! I hate Windows, the XP version, especially. Windows NT is better. Linux tries to convice the Linux' illiterates to love it ! Please hate Windows 7, which is similar to Unix. My laptop is too old for such a version. How nice that SUSE is so fast, in comparison with windows xp with its whole series of patches. I must accept the existence of MAC OS X. I have no Mac computer or laptop. I am an "old fart" man. I know, I'm a pensioner ! Windows xp is a rich widow. She has many older "pros?lites", en fran?ais.


smb.conf has a lot of options. Always follow the guidance provided in the top of the smb.conf/smb.conf.master file and use the testparm utility to fill the conf file or your Samba server could slow to a crawl.


use one of the distros that has the DrakXtools installed, a 7 mouse click process. [ check the video post Sonja is putting up about LAMP stack. I did full LAMP stack, FTP server, Samba Server and ssh server in a few minutes, no command line or conf file editing. ]


Samba 4 is the next step in my plan to wipe Microsoft products from the rolls of my company server lists. Now if only I could do the same with Office...


hehe, this wasn't the title of the article as I submitted it. =) I'm not claiming it's the easiest way. Initially I had called it "quickly share files with Samba", which is probably more apt a title. Regardless, this is a pretty cross-platform tip -- works on anything that Samba will work on. The same can't be said for the drakXtools.


when the drakxtools are only perl scripts that is inaccurate. :p perl will run on ALL platforms. [ except maybe idiot phones. ;) ]


... it's not a matter of having alternatives, it's more a matter of getting people to change their habits and the alternatives not being able to support all of the new Office formatting shenanigans.


Really? Try running drakXtools on Windows and let me know how that works for you. The tools were written for Mandriva, so they make certain assumptions. Same as YaST for SUSE. You wouldn't get 100% working functionality of drakXtools on Fedora or SUSE I bet. Mandriva-clones, where paths and configuration files are the same, perhaps, but unless everything is idential (i.e. smb.conf in /etc/samba/smb.conf and not /etc/smb.conf or some other location), I think you'll be disappointed. Just because it's written in perl doesn't mean it will work, even if perl is available. But, seriously, tell me what other platforms you've run the drakXtools on and I will gladly eat my words. (Not just run on, but actually made to do something useful)

Editor's Picks