Linux

Samba File Sharing Configuration and Tutorial

Samba file sharing allows a competent system administrator to configure a Windows-like network share on a Linux system. These shares are accessible by Windows computers and other SMB clients. Samba is software that makes it easy to exchange data with Windows operating systems.

What is Samba?

Samba is free software for Linux that implements SMB like functionality into the system. SMB is the dominant file sharing protocol used on Windows systems. By recreating this functionality, Linux systems can integrate into a Windows environment and function as both a client and/or a server. The software includes a dozen core services to make this possible.

Samba file sharing HOWTO

In this samba file sharing tutorial I will show you how to setup a Samba share with basic user access controls. You will learn to share a folder with read/write access and grant permissions to select users on the network. A mapped network drive on the Windows machine will serve as easy access to the Samba share.

This is a basic process that involves installing the Samba file sharing software and making a few configuration changes to the configuration file.

Installing Samba

Samba may or may not be installed on your system. Here are a few ways to install the software on various Linux distributions.

Debian/Ubuntu

apt-get install samba

CentOS

yum install samba samba-client samba-common

Arch

pacman -S samba

By default, the Samba configuration file is located at /etc/samba/smb.conf and comes extremely bloated. I always delete the contents and start fresh with only the configuration directives I require. If this scares you, make a backup of smb.conf first:

cp /etc/samba/smb.conf /etc/samba/smb.bak

The following configuration file will grant your username full access to your home directory on your Linux box. Copy and paste the contents below straight into the smb.conf configuration file. Be sure to substitute your own parameters on each line.

[global]

# Copy this into your /etc/samba/smb.conf configuration file

workgroup = WORKGROUP
netbios name = SAMBA
security = User

[data]
path = /home/user/
valid users = username
read only = no
create mask = 0777

There are a few parameters here worth mentioning.

workgroup should be the same name as the workgroup your Windows machine is on. The default Windows workgroup is called WORKGROUP, conveniently enough. You can verify this by going into your system properties.

netbios name is the name your Linux box will present to the network. Essentially, this is the name that will show up when you browse the network for connected hosts.

security is a setting used to determine how a particular share is accessed. In this case, we only want to grant permission to users that exist on the Linux system.

[data] is the name we are specifying for the share.

path is the absolute path of the folder we want to share to the network

valid users specifies what users should have access to this share. All other users not on this list will be denied access.

read only = no makes this share writeable by the users.

create mask sets the default permissions for this share. In this case, we grant full permissions to the owner of the files while completely denying permission to everyone else.

That’s all there is to it. Save the configuration file and then reload the Samba configuration:

service samba reload

The last thing we need to do is create a special Samba password for your user:

smbpasswd -a user

Your share should now be accessible from any Windows machine on the network. You can access the share by specifying the UNC or by browsing the network via Windows Explorer. Double clicking the share will prompt for a username and password. Plug in the credentials of your Linux user and click OK.

samba-file-sharing

Once logged in you will see the share you set up in the Samba configuration:

samba-configuration

Nice!

Troubleshooting

Problems with Samba are usually caused by incorrect configuration settings, permissions, or service related issues. A good starting point if you’re having problems connecting to your server is to check the Samba service status:

service samba status

Is the service running? If not, you’ll have to find out why.

Next, make sure there are no typos in your Samba configuration file. A single typo can throw off the whole server. Comb through your /etc/samba/smb.conf and make sure all your directives are correct.

Access denied problems can crop up if your permissions aren’t set correctly or you failed to set an smbpasswd for your Linux user account. Make sure the account you specify in the Samba configuration is active on the system and that you created an SMB password for the user. Re read the sections above for instructions.

Conclusion

Samba file sharing makes it easy to exchange data in a Windows dominant environment. You can see how easy this was to quickly get a file server up and running. Once again, Linux proves itself to be a very capable server operating system. Best of all, the software is free! This tutorial covered a very small aspect of Samba. If you’d like to learn more about Samba and its full capabilities, check out the official documentation or run through the man page.

 

Leave a Reply

Your email address will not be published. Required fields are marked *