Create a Linux Home File Server with Samba

Create a Linux Home File Server with Samba
Page content

What is Samba?

Samba was created as a means for Windows and Linux machines to be able to share files and printers. But Samba branched out further than that so that Linux machines could share files and printers as well as Linux and OS X could share files and printers. Samba is a very flexible tool and can be implemented easily.

Installing Samba

Installing Samba is simple. Open up your Add/Remove Software utility (should be found in your Administration menu) and do a search for “samba”. You will want to install the following: samba-client, samba-common, samba-server, and samba-winbind. Depending upon your setup there might be dependencies to meet for the installation (the Add/Remove tool will take care of this).

There is also a tool called gsambad that is a graphical client for configuring Samba. You can install that if you like, though it is not necessary.

Once Samba is finished installing issue the command /etc/rc.d/init.d/samba start (as the root user) to start the Samba daemon. If you are using a Ubuntu-based machine you will issue the command sudo /etc/init.d/samba start.

Setting up users

What I like to do is create a specific user for Samba to log in with. By doing this you do not have to worry about giving out specific user passwords to other users. So first create the new user. For example’s sake we’ll create the user sambauser to do this issue the command (as root) useradd sambauser.

Now that the user is there you have to now add the user to Samba. Issue the command (as the root user or add “sudo” if you need sudo rights):

smbpasswd -L -a sambauser

at which point you will be prompted to give a new password for the Samba user. Now issue the command:

smbpasswd -L -e sambauser

which will encrypt the samba user password.

Configure Samba

Now it’s time for the actual configuration of Samba. In the /etc/samba directory you will see the file smb.conf. Edit the contents of this file so they look like:

[global]

netbios name = NETBIOS NAME

workgroup = WORKGROUP NAME

security = user

encrypt passwords = yes

smb passwd file = /etc/samba/smbpasswd

interfaces = 192.168.1.1/8

[SHARED DIRECTORY]

COMMENT

path = PATH_TO_SHARED_DIRECTORY

writeable = yes

create mode = 0600

directory mode = 0700

locking = yes

Notice everything in caps, these are the items of the configuration file that will need to be specific to your network/needs. Also notice the “interfaces” entry. If your network uses a different IP address scheme make your changes here.

Once you have the configuration in place, save the file, and restart samba.

Connecting to Your Samba Server

Now that you have your Samba server up and running, let’s connect to it. Below you will find instructions on connecting from Linux, Windows, and OS X.

OS X: Connecting with a Mac is easy. From within the Finder click the Apple and the “k” key at the same time. A new window will open up asking for the information to connect to the Samba server. For the server address you will enter smb://SERVER_ADDRESS (Where SERVER_ADDRESS is the actual IP address of the Samba server.)

Linux: Open up your file manager (Dolphin or Nautilus) and enter smb://SERVER_ADDRESS (Where SERVER_ADDRESS is the actual address of your samba server.) You will be prompted for the username and password.

Windows: This is not as easy. First you have to configure your machine to connect to the workgroup you have configured.To get to this tool you right click on My Computer and select “Properties”. In the Computer Name tab click the Network ID button and enter the workgroup you configured in your smb.conf file. You might have to reboot your machine. But once you are up and running you should be able to go to My Network and see your workgroup. You can also open up Explorer and enter \\SERVER_ADDRESS in the address bar (Where SERVER_ADDRESS is the actual address of the Samba server.)