Open Source

10 ways to make your Samba life easier

Samba allows Linux, Windows, and Mac to communicate with one another, but it has a reputation for being tricky to configure and administer. Here are some ways to reduce Samba headaches.

Samba is essential for many SMBs. Not only does it work like a champ as a file server, it does so at zero software cost. The biggest hurdle to adoption is what most people consider to be complicated setup and administration. Like many assumptions about the Linux operating system, that's a myth. Samba does not have to be a challenge to configure or administer. In fact, it can be downright simple. Here are some tips to make your Samba life is as painless as possible.

Note: This article is also available as a PDF download.

1: Share folders from your desktop

The two main desktops, GNOME and KDE, now have easy tools to facilitate sharing folders with the help of Samba. If Samba is installed (as well as kdenetwork-filesharing, nautilus-share, and libpam-smbpass) on the machine, all you have to do is right-click a folder, select Share Options (in GNOME) or Properties | Share tab (in KDE 4). When you set sharing up this way, you won't have to configure Samba by hand.

2: Use a GUI tool, such as Gadmin-Samba

If you don't use GNOME or KDE (or would rather have a GUI tool that has more options and security), you can easily install a tool like Gadmin-Samba to take care of your Samba configuration/management needs. This tool doesn't help with GUI-less Samba servers, but it will certainly help anyone needing an easier means of configuring Samba than cracking open that smb.conf file.

3: Don't forget to add users with smbpasswd

One of the biggest mistakes I see with setting up Samba is forgetting to add users to the smbpasswd file. This is easily done using the smbpasswd command like so: smbpasswd -L -a USERNAME (Where USERNAME is the name of the user you want to add) and smbpasswd -L -e USERNAME (again, where USERNAME is the name you want to add). If you don't add users to the smbpasswd, they're going to have a lot of trouble connecting.

4: Use the mode/mask options

When you (or your users) want or need to create files and folders on the Samba share you're connected to, the parent folders must have been created with the right permissions. To ensure this happens, you must add the create mask = 0777, create mode = 0777, and (if your share is being particularly stubborn) force create mode = 0777. These will ensure that all directories/folders created within the parent have read/write permissions. NOTE: Use this with caution, as it does make those directories/files fully read/writable.

5: Create smaller shares instead of one big share

Some people are tempted to create one big share that all users can access. This can cause a problem because all users will be able to access the entire contents of the folder. Instead of this approach, create smaller shares allowing only specific users to access them. This will give you better control over security and a better file system structure.

6: Don't forget to restart Samba

This one trips up a lot of people. If you make a change to your Samba configuration, make sure you restart Samba. You do this with a command similar to sudo /etc/init.d/samba restart. It's an easy step to overlook.

7: Use the right security mode

This is a hotbed of contention. Most want to go the route of uber paranoia (and I do not blame them). The only problem is that it does make your Samba setup much more complicated. My preferred method (and this is ONLY on a secure internal network) is to use security = user, which means anyone that has an account on the server serving up Samba shares has access to the shares. There are actually five modes of security: User, Share, Domain, ADS, and Server. Check out this page for a detailed description of each.

8: Keep the smb.conf file simple

When you install Samba, the /etc/samba/smb.conf file can be rather confusing to the uninitiated. This confusion, ironically enough, is generally due to the amount of comments in the file (comments meant to make understanding the file much easier). The configuration file really only needs (at minimum) a [Global] and a [Share] section. The cleaner and more minimal you keep this file, the easier it is to set up. I always just make a backup of the initial file and create my own smb.conf file that looks similar to this:

[global]
netbios name = NETBIOS_NAME
workgroup = WORKGROUP

security = user

encrypt passwords = yes

smb passwd file = /etc/samba/smbpasswd

interfaces = 192.168.1.1/8

[SHARE]
comment = COMMENT

path = /PATH/TO/SHARE

writeable = yes

create mode = 0750

locking = yes

Configure this to suit your needs and you're good to go.

9: Automount using /etc/fstab

A lot of people don't know that you can use /etc/fstab to automount your Samba shares. By doing this, you won't have to manually mount those shares every time you reboot (which is rare anyway, right?). A typical /etc/fstab entry for automounting a Samba share will look like this:

//SAMBA_SERVER_ADDRESS/SHARE     /PATH/TO/MOUNT/POINT    cifs  credentials=/etc/samba/user.cred 0 0

10: Learn how to "cross-platform connect"

Because Samba is so friendly to most every operating system, why not learn how to connect to a Samba server from Linux, Windows, and Mac? Each OS has a different method. Let's take a look.

  • Linux: The best method is in GNOME. Click on Places | Connect to Server. You will want to select Windows Share.
  • Mac: From the Finder click <Apple>k and enter the address of the server in the form smb://ADDRESS_TO_SERVER.
  • Windows: Open up Explorer and enter \\ADDRESS_TO_SERVER.

Use caution

Don't forget: Always consider security first. Make sure your network is safe from unwanted users and traffic before opening up Samba to anyone and/or everyone.

Your turn...

These tips will make your life with Samba much simpler. Do you have other tips to add to this list? If so, share them with your fellow TechRepublic members.

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

7 comments
Neon Samurai
Neon Samurai

I started with Draketools and Mandriva back in the day. Webmin is good for doing the config work though and removes the need for an X install. The config file is also pretty strait forward so these days it's direct to text more often than through a tool. With #9, I'd suggest looking at how the connection is handled. I had trouble with perminent mounts getting disconnected then not reconnecting. The solution was smb4s within a GUI or an auto-mount tool outside of GUI so that I'd get an ad-hoc connection when entering the mount directory.

snelson
snelson

Jack, What do you think about using WebMin to manage Samba?

oldbaritone
oldbaritone

ever since I shut down the W2K server. I just moved the drives to linux, mounted them, and recreated the shares. Windows works just fine with Samba; the users don't even know what the shares are not coming from a Win server.

Juergen Hartl
Juergen Hartl

And this another reason Linux is light years away from a wide spread acceptance as desktop OS.

tbmay
tbmay

You can't have include directives in your config though...at least last time I installed it. I put it on servers clients will be administering as long as there are no unusual setups (i.e. username to ip authentication, etc)

j-mart
j-mart

Its purpose is to connect various desktop OS's to Linux/Unix server. It does this with great reliability and for the IT pro is not too hard to set up. for someone in the "TRADE" if they can't work their way through a samba set up they possibly have chosen the wrong career. There are many advantages to using Linux servers over windows servers both in cost and performance and it is not that difficult to learn how to connect windows desktops to a Linux server, most of what's required can be easily picked up with a bit of googling. I myself prefer to directly edit the samba configuration file, as you can see from the example given in the article this is simple enough.

tbmay
tbmay

There are many reasons but the biggest one is open source coders and users have only recently started caring about it getting market acceptance. Microsoft is a company, and as such it needs market acceptance. I use Linux and BSD all the time in my business on servers, firewalls, VPN's, etc. I DO NOT try to get clients to use it on their desktops and doubt I ever will. Those Samba tips are fine for general things. You can't keep it that simple for every deployment though.