Stepping Into Samba
This post was published 4 years 9 months 7 days ago which may make its actuality or expire date not be valid anymore. This site is not responsible for any misunderstanding.A few friends of mine stare at me blankly when I mention Samba and SMB. In fact, sometimes they think it’s the same thing, when in fact, it’s not. I’ll talk about the differences between the two and walk you through setting up Samba networked shares. This will give you a nice introduction to Samba and also Linux, if you are not familiar with that, also.
The real question here isn’t why SMB, or why Samba for that matter? Well, first off, after I explain to you what SMB is and then explain what Samba is, you’ll see that this question I just asked was mildly stupid. The actual question here is “Why create network shares in the first place?”. This is a very basic, honest question, but it tends to turn a few heads. I’ll give you a scenario. You have 5 computers in the house; your laptop, your desktop, the kids have two computers, and your wife has her school laptop. So, your wife has school work and her latest favorite songs on her laptop, the kids have theirs, and you have all your applications and whatnot all on your laptop and desktop. What might seem like not that much data, turns into gigs of data. You have tons of music, school reports and research, ISOs and applications, Development related stuff, pictures from the past four years. You notice you are running out of space on your kid’s computers and you wife’s laptop is running a little sluggish. Now, this is probably highly due to the games and occasional pop ups that are clicked, but hey, why take up space on the systems, when everything can be centralized? Yes, that’s the word – Centralized.
What is SMB
SMB stands for Server Message Block. In a nutshell, SMB is a protocol that was modified, heavily, by Microsoft. There’s a timeline involved here, but mainly Microsoft modified SMB and it turned into what is now called Microsoft Windows Network. Just want to make it known that SMB is NOT Microsoft Windows Network, but it’s the model and protocol Microsoft used to develop what is now known as the Microsoft Windows Network.
Then, what is Samba?
Samba is Samba. Just like my name is Drew. Samba is an application. Fortunately, that’s not all it does. Samba is a reimplementation of the SMB protocol, which is released under the GNU license. Most of us who install Samba, will be running version three. Samba version three provides file and printer shares (just like the Microsoft Windows Network), but also allows you to integrate Samba with a Windows Server domain, which goes beyond the scope of this article. Samba was designed for a Unix environment so that it (Unix) could communicate with Windows-based networks and file shares. This allowed Windows-based systems to be able to access data on a Unix machine, via file shares.
Planning
I think for the most part, in anything you do, at least 80% of the time, you plan things out – at least you should. What we need to do before configuring, installing, or implementing anything is figure out how out network will be laid out, what shares we want to make available, what shares we want to implement but not make available, and how we want to make this as seamless to the rest of the family (or employee’s, etc). I am using family members in this case to make it an easier approach, as this is not along the lines of a internal network infrastructure. If this was the case, you would probably be interfacing the Samba server with a Windows Server domain, etc. We are not. Period.
The Operating System
For the operating system, we will need to run Linux, as Samba is primarily supported on Linux, not Windows, and we wouldn’t need to use Samba if we were using Windows. If you are fairly new to Linux, I would use Ubuntu, and if you are a Linux novice, use whatever you would like, but in this case, I will be using Ubuntu as this article was written for a introduction, not someone that knows a whole lot about Unix. As you can use Ubuntu Desktop as you wish, I will be covering everything via the command line, in which I recommend you use Ubuntu Server, even though it is not required.
The Network
To plan a small network like a home network, sometimes referred as a SOHO network, doesn’t need much planning, but is worth the time to think out. You have your modem/router or your modem to router connection – some ISP’s lease you a modem that has a built in router, others just give you a modem and if you want routing capabilities you must go purchase a router yourself. If you can, run the server off of the router or even another switch. The least amount of network devices you have between the router and the server, the better. Either way, make sure it is wired into your network, do not use wireless. Next, you must think about your clients. I presume that your laptops have built-in wifi, therefore you must have a wireless router or some type of wireless access point that is inside your internal network. You can connect to your server via wifi, as long as you’re on the same subnet, in which, in a SOHO environment, if you can get on the internet, you’re on the same subnet; in an enterprise environment it isn’t this easy. Then you have your other desktop computers. More than likely if you do not have a network drop or anything implemented in your house, then you probably have a wireless solution, which is the easiest way to network computers these days, but the internal network speeds that wireless offers and that allow you to stay within budget aren’t as good as a wired solution. This too, I will not really go into, as this is somewhat beyond the scope of this article. I mentioned a switch earlier. If you decide to go the wired solution and you have a network device (hub, switch, bridge) connected to you router that then gets connected into your systems, I beg of you to use a switch. Do not, I repeat DO NOT use a hub. A hub broadcasts ever single packet you send to all the other computers and thus creates a huge bottleneck and therefore creates packet loss and intermittent network connectivity, especially if you are all trying to access resources on the server at the same time.
Network Shares
What would you like to share, or at least make available to your via a remote connection. When I say remote connection, I mean not on your local computer, but still inside your internal network; if you want to make your local system available remotely (throughout the internet) you would need to setup a VPN. This step would probably be best on paper. Just to give a few ideas, you could make network shares for public (this would be good for sharing your files with you family), you can make shares for each family member, if you are a programming you can setup a code repository share, and xfer share is always good for temporary storage, a share for pictures, music, and videos is always good to have also. Of course, all the shares you setup is totally dependent on what you want to do and what you have in the way of data.
Installing Samba
As stated before, I will be covering everything via the command line, which means I will not talk about the GUI, and you will need to know how to open up your console. Note: If you are running Ubuntu Server there is no GUI, therefore you will already be in a console. I will walk through the Ubuntu way of doing things, which actually might work on a Debian system also, as I will be using apt-get. To actually install Samba, you will need to issue the following command:
apt-get update apt-get install samba smbfs |
First we run apt-get upgrade to update all the application repositories so that we can get the most recent version of the software for the Ubuntu distribution. Then we run apt-get install samba smbfs to install Samba and its dependencies. That’s one of the greatest features of Aptitude, that it downloads and installs the dependencies of the application if they are not already installed. Takes alot of pain of of installing dependencies with weird application output messages.
That’s it! Samba is installed. Now it’s time to configure your network shares, resources, and settings.
Configuring Samba
There are pages, pages, and more pages of Samba configuration options that can be found here.
Creating Samba Users
We can create users first, or we can create Shares first; doesn’t matter. We will be creating our Samba users first. Creating users is very easy, as there is already a command that does this for you. By default, Samba uses the /etc/passwd file to authenticate new users, therefore, before creating a new Samba user, the user has to exist on the system already. If the user is not already in the system, then Samba will error out and will not create the new user. The smbpasswd command is the command you will need to use to create new users. As you can see, it looks like the Linux passwd command. There are many options you can use with this command, so have a look sometime (smbpasswd --help). Now, let’s create a test user, in which we will name the user test-user:
smbpasswd -a test-user New SMB password: [password to be typed here] Retype new SMB password: [retype your password here] |
Just like the passwd command, it looks the same. If the passwords matched and the user existed in the system, then it should say that it successfully created the new user and you should be able to use that new user on a Samba share. Please note that there are different ways to configure Samba, and this configuration is default so that you can get your Samba server up and running so that you can experiment with it. There are ways to configure Samba to not use the /etc/passwd file to authenticate users; check the documentation.
Creating Shares
As stated above, you will need to look at the documentation to go further with Samba, as I will only be covering basics here in which you can further build upon. Creating shares are faily easy, but requires your knowledge of editing files using a text editor. That sounds dumb, but some people have had little to no experience with Nano or Vi(m). Either way, you will need to open /etc/samba/smb.conf in a text editor of your choice. If you cannot find smb.conf in the path I stated, try running the following commands:
updatedb locate smb.conf |
That should let you know where it is. Also note that there may be multiple entries and you would need to pick the one that makes more sense, depending on where the file is located and you understand the Linux file system logical organization (if that makes sense). For this example, let’s create a share called xfer. This is a very popular share name, which stands for transfer. It’s like a holding spot for temporary files that you will be getting around to soon, but not at the moment. This is what I use it for.
Now, first off, you have to know how the Samba shares work. They actually share folders/paths from your Linux server (just like Windows) to a share name, so you must have the actual folder in place for this to work. So, if you don’t, let’s create a directory called data in the root filesystem and then create a folder inside there called xfer. To do so, run the following command:
mkdir -p /data/xfer |
The -p option actually creates the parent folders, so that you don’t have to run mkdir on each individual folder; neat. Note that if you are logged in as root and you created that folder (which is more than likely the case), the permissions on the folder will be 755 (read, write, execute for user, read and write for group and other) and the owner and group will be root. This could pose a problem when adding users to the share, as they might get access denied errors when tryign to write to the share. You would need to chmod and/or chown a few things around to rectify this issue, if need be. Use the comments form below if you have any issues like this and I’ll try to get you through it.
Now, before we create our share, let’s configure the Samba server. Open /etc/samba/smb.conf in a text editor of your choice (feeling a little repetitive). There’s going to be alot of stuff in here. Towards the top you will see a [global] option; in here is where we need to configure the server. For simplicity’s sake, just edit the workgroup to whatever you would like. The workgroup would just be like a name that you would be connecting to, kind of like Windows. For this article, we will use testgroup:
workgroup = testgroup |
Now, you can save that if you would like, but don’t close this file, as we need to now create the new share. Scroll way down until you see a section that says Share Definitions; this is where you will need to create your shares. Little side note: you really don’t need to scroll down and create your shares here, it’s just how this document is organized and it’s sometimes good to start easy and work your way up, so don’t sweat where you actually put the share name, just as long as it follows the format I will cover here in a second and that it is in this file (/etc/samba/smb.conf).
The format of the share definition is the share name, followed by all of its configuration entries. I will explain after you see and add the actual share:
[xfer] comment = Xfer Share path = /data/xfer guest ok = no browseable = no writeable = yes valid users = test-user admin users = test-user |
Make sure you save your smb.conf file and close it.
Let’s cover what all this means. The [xfer] part is the actual share. This means you will access the share by typing the IP address of the server followed by a backslash () and the share name (xfer). You can also use the workgroup name instead of the IP address. The path option is the local system path to what you are sharing, which is not seen by the user who is accessing the share. The guest ok is an option to allow a guest user. I have alot of files on my system, I am have no reason to share to a guest, but you may if you wish; I do not allow this on any of my shares. The browseable option is to tell Samba whether or not to allow the share to be browseable when accessing the Samba workgroup. This may sound confusing, but it’s actually quite easy. If you access your Samba server by using the IP address you will see all the shares that are browseable, and by stating that you do not want it browseable, it will hide the share, but is still accessible. This option is like Windows’ share + $ way of hiding shares. In Windows, it would be the share name and you would add a $ to the end of the share name. The writeable option is to allow the share to be writable by the user period. If the user actually doesn’t have the ability to write to it because of Unix permissions (on the server itself), then you will not be able to write to the share anyway, but if the share is not writable whatsoever, then it will not be able to written to at all. The valid users option is to tell Samba what users are allowed to access the Share. If you do not put the user you want in here, then the user will simply have no access to the share at all; not even read access. The admin users option is allows a user or group to have root permissions to that share. This is good, and bad. This would be good if you had a person that should have root privileges to a share (such as an administrator), but it would be bad if you assigned it to a group and didn’t realize that you just gave all your users root privileges on a share.
I will say it again, these are basics. You don’t have to use these, but some of these options are required.
To test your smb.conf for errors, issue the following command:
testparm /etc/samba/smb.conf |
It is always good to test your smb.conf for errors so that you can limit the amount of errors, before pushing the changes to the server. When you beleive that everything is working correctly and you are ready for the new changes to take effect, restart Samba:
/etc/init.d/samba restart |
Note that there are alot of ways to restart Samba, and that the Samba service can also be abbriviated as smb, so if you get any errors stating that the service is not found, try a few different things to see if that fixes the issue.
Accessing Your Share
Accessing your share is easy, as long as you followed the above directions. Most people set up Samba so that they can access their files on a Linux Server from a Windows machine, so we will be accessing our Samba server from Windows. Remember back in the article I stated we would be using the workgroup testgroup and the test user called test-user? This is where this comes into play. The easiest way to test your Samba server by connecting to to connect to it via Start…Run. Go to the Start Menu, select Run… and type in \testgroupxfer and press enter. This should display your Xfer share and its content (if any):
Now, say you want to actually have your xfer share to connect every time you login. This is usually what you want, so that you can access the files on your Linux box from Windows without having to manually access the shares. To do so, we will need to map the network drive to your local Windows machine. To do so, right click My Computer and scroll down to Map Network Drive…:
You will then be presented with a Map Network Drive dialog box asking you what drive to assign it and what network path we will be using (path to the Samba workgroup and share). In this example, we will use drive letter T: and the path to the share would be what you tested with before using the Start…Run method (\testgroupxfer). Make sure you also have the checkbox checked next to Reconnect at logon:
When completed, you should see your drive letter in My Computer:
Wrapping It Up
Although this seemed like it was going to go on forever, it has finally come to an end. Overall, setting up a simple Samba server is easy and usable, and very highly configurable. I recommend you have a look at the core documentation and see what you can do with Samba.




May 1, 2007
What took you so long? :-D LOL
Thanks so much for this. I’m going to finally buy the drives. I’m working on experimenting with Ubuntu Desktop (6.0.6). No new version because of my computer problems. :-)
Nice new theme! Very Professional.