I recently did an illustrated guide to installing Ubuntu Server 9.04 ("Installing Ubuntu Server 9.04"). I did that for two reasons: 1) It was requested and 2) It will serve as a base for future articles that will cover many different topics. Having that foundation will be key to getting other services up and running.
In this article I am going to show you how to get a basic Samba Server up and running on top of that Ubuntu Server. Now, because the Ubuntu Server was set up as a headless server, the installation and configuration of Samba will be done completely from the command line. So get your fingers ready to type.
What is Samba?
Samba is a very handy tool that can do many things. The primary task it serves is to enable a Windows machine to access a Linux machine serving as a file and/or print server. Samba uses the SMB/CIFS protocols to enable communication between the Windows and the Linux machine.
Samba has often been thought of as very difficult to get up and running. It's not really that bad. Hopefully, by the end of this article, you will have a fairly good understanding of how to get it up and running.
As I said, you will doing this completely from the command line. The command to issue is:
sudo apt-get install samba
You will have to enter your sudo password to continue with the installation. Depending upon your server installation, you might have to okay some dependencies. Go ahead and do this and then watch as Samba is installed.
Once installed you will have the Samba executable in /etc/init.d/. In order to start Samba you will issue the command:
Of course, before you start Samba, you will need to configure Samba. There are a few steps to take care of. Let's first deal with the configuration file.
Before you get too deep into this you might want to first read my article "Get To Know Linux: Understanding smb.conf". The Samba configuration file is located in the /etc/samba directory and is called smb.conf. When you first open up this file you may be overwhelmed. Let's avoid that by making a backup of the original smb.conf file. Change to the /etc/samba directory with the command:
Now issue the following command:
sudo cp smb.con smb.conf.bak
Now you can open up the smb.conf file and erase the entirety of its contents. How do you do that? If you are using the Nano editor it's simple. With the file open hold the Ctrl key and the 'K' key down until the entire contents are gone. Or you can delete the file and create a new one. Your choice.
With a fresh smb.conf you are ready to re-create a file based on your needs. A good configuration to start with looks like:
netbios name = NETBIOS_NAME
workgroup = WORKGROUP_NAME
security = user
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
interfaces = 192.168.1.1/8
comment = COMMENT
path = /PATH/TO/SHARE
writeable = yes
create mode = 0600
directory mode = 0700
locking = yes
Where everything in ALL CAPS (as well as the interfaces line) is unique to your needs.
The SHARE_NAME is what you want to share out to your users. So if you are setting up a file server for a number of users you will want to have a directory, say /data, that is shared out through Samba.
Once you have the smb.conf file configured to suit your needs you are ready for the last steps.
This is the step that most people skip and wonder why Samba isn't working. For every user that needs to log in to the Samba server you have to add them with the help of the smbpasswd command. Let's say I need to add the user "pickles". To add "pickles" I would issue the command:
sudo smbpasswd -L -a pickles
Now to make sure the users is enabled issue the command:
sudo smbpasswd -L -e pickels
Now restart Samba with the command:
sudo /etc/init.d/samba restart
Your Samba file server should be ready to go. Go to your windows machine and the Share should be visible. Double click on that share you and you will enter the username and password combination for any one of the users on the machine (as long as they were also added with smbpasswd). If you can not see it make sure your Windows machine is set up on the Workgroup.Advertisement
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.