How to setup a fileserver with Samba on Ubuntu 10.04 LTS
Posted in "News"Ubuntu smb cifs samba fileserver
Having a file server at home is very useful if you want share documents across multiple computers.
You can set-up multiple shares for music, films, documents... It could even be very useful if you login from multiple computers in your local network to centralise your home directory and those of other users too!
This article will explain how to set-up a basic working Samba file server with Ubuntu 10.04 LTS. You will need a working Ubuntu 10.04 LTS server to start with of course!
Update your package manager and install Samba:
sudo apt-get update sudo apt-get install samba smbfs
Follow the default prompts to install Samba.
2. Create the directory to share.
Before changing anything in the Samba configuration, you should create the directories that you want to share. We will create a music share which all users can use:
sudo mkdir -p /home/shares/music
We need to change the owner to the "users" group:
sudo chown -R root:users /home/shares/music/
Make the directory writeable for all users:
sudo chmod -R ug+rwx,o+rx-w /home/shares/music/
3. Add and manage users and groups.
This command will create a new Linux user with a home directory and password.
sudo adduser <username>
Follow the default prompts to complete the process. You can add as many users as you want like this, just replace the <username> with the desired username in the commands. Since our group is named "users" we will need to add our new user to that groupname! In this example we will add user "dave" to the "users" group
sudo adduser dave users
If you want to create other groups for other shares you need to use this command:
sudo addgroup <groupname>
Now, Samba uses a separate set of passwords than the standard Linux system accounts (stored in /etc/samba/smbpasswd), so you will need to create a Samba password for each user you have added with this command:
sudo smbpasswd -a <username>
You can use the same password as you have used when creating the user if you like, or you can use a different password which is more secure.
Go to http://help.ubuntu.com/community/AddUsersHowto for more information on how to add and manage user accounts.
4. Configuring Samba.
The configuration file is located in /etc/samba/smb.conf, but before editing we should create a copy as backup!
sudo cp /etc/samba/smb.conf /etc/samba/smb.backup.conf
Now we are safe to edit the Samba configuration for our needs:
sudo nano /etc/samba/smb.conf
Find the line called "workgroup = WORKGROUP" (without the quotes), remove the ";" at the start of the line and change the workgroup to the workgroup name you use in your home network. For example
workgroup = EXAMPLE
Next find the line "security = user" (without the quotes) and remove the ";" at the start of the line. This requires clients to supply a username and password to connect to shares (The user name of the Linux account and the matching samba password you have created).
Now we will add the directory that needs to be shared by Samba. In this example we use the directory "music" which we have created earlier.
[Music] comment = Our digital music collection path = /home/shares/music valid users = @users force group = users create mask = 0660 directory mask = 0771 writable = yes browsable = yes
Let's take a moment to explain all parameters:
- Comment: this is used to give a description about the share.
- Path: the actual path to the directory you want to share.
- Valid users: add users or groups that can have access to the share. separate by space (For example adding only certain users "valid users = user1 user2 user3" or multiple groups "valid users =@group2 @group1" in this case we use only the group users "valid users = @users").
- Force group: This specifies a UNIX group name that will be assigned as the default primary group for all users connecting to this service. This is useful for sharing files by ensuring that all access to files on service will use the named group for their permissions checking. Thus, by assigning permissions for this group to the files and directories within this service the Samba administrator can restrict or allow sharing of these files.
- Create mask: sharing security level for the files.
- Directory mask: sharing security level of the directory.
- Writeable: used to set the share writeable or readonly (you can use the parameter "read only" instead if you like for example: read only = yes)
- Browseable: This controls whether this share is seen in the list of available shares in a net view and in the browse list.
For a more detailed explanation about all usable parameters, click here.
Finally, restart the samba services to enable the new configuration:
sudo restart smbd sudo restart nmbd
5. Testing Samba.
To test if your configuration works, use this command:
If no syntax errors show up, you are good to go.
Test on another computer if your Samba "music" share is reachable, enter your Linux username and your Samba password to connect to the share.
For a tutorial on how to connect your Samba share (network drive) in Windows, check this Microsoft support article.