How To: Use Ubuntu as a File Server with Samba (SMB Sharing)
Ubuntu is a highly popular and flexible distribution of Linux that can serve many purposes, one of the most common and practical of which is a file server, especially in situations where your client(s) can't access a Windows file share.
Download & Install Ubuntu
Ubuntu was released in 2004 to provide an easier Linux desktop. Today, Ubuntu is employed in a wide array of settings, from desktop to server, enterprise and cloud solutions.
You'll want to begin by downloading the latest version of Ubuntu Desktop. This is the simplest and most user-friendly type of Ubuntu installation to complete. For help with installing Ubuntu Desktop, see Canonical's installation guide for Ubuntu Desktop.
If you are comfortable with Bash, the command-line interface found on most versions of Linux and Unix, you can also follow these instructions for an installation of Ubuntu Server (with a few minor differences).
Install the necessary packages & tools
Released in 1992, Samba is an open-source software developed to make sharing between Windows and Linux systems easier. While it may seem a simple software for file and print sharing, Samba can do much, much more and is a truly robust tool for many home or business settings.
Open up a Terminal and run the following commands. Enter any information and confirmations necessary to proceed after each command.
sudo apt-get install gksu sudo apt-get update sudo apt-get install samba
These commands install a tool later in this process, update your packages and then installs Samba, which makes this type of file sharing possible on Ubuntu.
Create a share and account(s) for accessing it
Next, create a new folder in the logged-in user's home directory, (located at /home/[username] without brackets). We'll call it "SHARE" for this tutorial.
For Ubuntu Server, you can do the same thing with these commands:
cd /home/[username] mkdir SHARE chmod SHARE 777
Now go back into Terminal, here you'll use the following commands to create a user named 'bob' with a password of your choosing for file sharing and set password for this user in addition to the username you're logged in as. Remember these as you'll need them to access the share later.
sudo useradd -s /bin/true bob sudo smbpasswd -a bob sudo smbpasswd -a [username]
Setup and test the share via its configuration file (smb.conf)
In Linux, gedit is the classic, default text editor for the GNOME desktop. Also a part of the GNU project, nano is a great text editor for use in the command-line interface, such as Ubuntu Server in this example.
Open Terminal and run the following command to open the Samba configuration file:
gksudo gedit /etc/samba/smb.conf For those on Ubuntu Server, you'll need this command for an inline text editor (use CTRL+O to save changes and CTRL+X to exit): sudo nano /etc/samba/smb.conf
Now scroll to the bottom of this file and add the following. Be sure to fill the space occupied by [username] with the relevant account you are logged in with.
[SHARE] path = /home/[username]/SHARE available = yes valid users = bob [username] admin users = bob [username] read only = no browsable = yes public = yes writable = yes
The commands above have added your shared folder to the Samba server and configured Bob and your logged in user for both normal access ('valid') and root access to this share ('admin').
You'll need to restart both services Samba depends on to make your changes live:
sudo service smbd restart sudo service nmbd restart
Now try and test your new share by visiting the UNC path at \\[computer name or address]\SHARE. If it worked, you've successfully figured out how to setup a smb share on Ubuntu using Samba — nice work. Read on to Step 5 for more information on advanced configuration for your shares.
Customize share users & permissions
Now that you've established a simple share accessible to computers running Windows, you can start to customize your folders, users and permissions to your own environment and needs.
Just as in the last step, these settings will be controlled by your Ubuntu users, Samba users and your Samba configuration file located at /etc/samba/smb.conf in the following format:
This tutorial is too small in scope to get into all the things Samba can do, so we'll stick with our run-of-the-mill example to understand how Samba is used in a common environment.