Samba is a useful service found in most Unix and Linux system that allows you to share file and print services with another computer, particularly a Microsoft Windows client. In Ubuntu, while the Nautiilus File Manager comes with a series of connection protocols to access files from a remote server, it doesn’t turn the machine into a file server and accept connection from other PC. Samba is the one that does the job. In this tutorial, we will show you how to install and configure Samba so you can turn your Ubuntu PC into a file server.
Samba is not installed by default. Open a terminal and type the following command:
sudo apt-get install samba
Alternatively, you can install Samba via the Ubuntu Software Center.
To get Samba to work the way we want it to work, we have to make some changes to its configuration file.
In the terminal,
gksu gedit /etc/samba/smb.conf
This will open the config file in Gedit.
Scroll down the page until you see the line:
workgroup = WORKGROUP
This is the identifier of your PC. You can keep it as the default, but it is best to change it to something more meaningful, like “HOME-DESKTOP”.
Next, scroll down further till you reach the “Authentication” section. You should see the line:
# security = user
Remove the “#” at the front of the line.
Continue to scroll down further until you reach the “Share Definitions” section. This is where you configure the files/folders that you want to share with others.
If you want the Home folder to be accessible, you should uncomment (remove the “;” at the front of the line) the following lines:
[homes] comment = Home Directories browseable = yes valid users = %S
Don’t forget to change the
browseable value to “yes”. You can also uncomment the
read only = no line if you allow others to write to your Home folder.
The last line
valid users = %S means that only you, or anyone with your login account, can connect to your own Home folder via Samba.
To add additional file sharing path, add the following lines to the end of the file:
[share] comment = New Share Path path = /path/to/share/folder browsable = yes guest ok = yes read only = no create mask = 0755
Change the name of this share configuration and change the path to the folder you want to share.
You can change the “guest ok=yes” line to “guest ok=no” if you want the share path only available for logged in users.
Lastly, save and exit the file.
Setting Samba user password
To add yourself to the Samba user list, you just have to type the following command:
sudo smbpasswd -a <username>
Replace with your username. It will then prompt you to set a password for this Samba account.
Alternatively, you can also create a new user account and add this user to the Samba user list
To create a user account, use the following command:
Restart Samba services
sudo restart smbd sudo restart nmbd
That’s it. You should be able to connect to this PC from another PC.
More Samba Tips
If you are looking for an easier way to configure the Samba settings, you can install “Samba Server Configuration” GUI.
sudo apt-get install system-config-samba
On your Nautilus File Manager, you can also right-click on any folder and select the Sharing Options to enable sharing.