Four ways to share files in Linux

by Andrew on February 17, 2013

in Training

1. Simple sharing with Samba

Windows has long allowed you to share a folder with other users on your local network with a simple right-click, and over that time the Samba project has done a good job of reverse engineering the Windows software, bringing the same functionality to Linux.

For the end user, that means in most distros you can share a folder by right-clicking on it. For example, on SUSE you right click on a folder, select properties and then click on the Share tab.

On Ubuntu just right click and select Sharing Options.


Let’s look at the options Ubuntu offers. Tick “Share this folder”. You can change the share name and add a comment if you like – the share name is what the folder will be called when it appears to others.

Guest access allows anyone on your local network to access your folder. It’s completely insecure, so don’t use this if there’s anything at all in the folder that you would worry someone stealing.

By default, the folder share is “read only” – others can see all your files but can’t change, delete or add files. You can change this if you want to allow more access.

Without guest access, anyone wanting to access the share must have a valid username and password for your computer. (You may need to create a Samba password for a user with the smbpasswd command – run from the command line).

The configuration options vary between distros. What they all have in common is, if everything is working correctly, the file share will be discoverable not just on other Linux PCs but on Windows and Mac too.

On Windows, for example, go to Computer > Network and browse the shared folder which should appear there (under the name of the computer it sits on). If you need to enter a username and password, you’ll be prompted.

2. Advanced Samba Sharing

Samba has a whole host of options – brilliant for flexibility but a potential nightmare when it’s not quite working the way you’d like it to.

For example, you can set up a Linux server as the Primary Domain Controller in a Windows domain and have different shared folders automatically mount on people’s PCs as they log onto Windows.

Remember that in Linux-land you can set up almost any Linux system as a server, so if you want to implement more sophisticated file sharing with your Linux PC, you can do. You’ll need to have the Samba software installed (in particular, smbd – the backend demon) and you’ll need to edit the /etc/smb.conf file which tells Samba exactly which shares to offer out and with which configuration.

In the /etc/smb.conf file you have some system wide configuration parameters and then a section for each share, which might look something like this:

[documents]
path = /share/documents
comment = shared documents folder
valid users = mike megan jenny
write list = mike megan
directory mask = 0775
create mode = 0775
read only = no
available = yes
browseable = yes
writable = no
guest ok = no
public = no
printable = no
locking = no

The exact options will depend on what you want to do, and you might need fewer or more than in this example. The big benefit is that this integrates with a Windows network, and can be used to serve files to Windows, Mac, Linux and other systems.

3. NFS

Samba may be the solution if you have Windows PCs in the mix, but if your computers are all Linux or Unix-based systems then NFS (Network File Systems) is an excellent option.

NFS has been in development for more than 30 years – it’s mature and suitable for enterprise use. In fact, you’ll find big companies across the globe using NFS in their mission critical systems.

NFS isn’t designed for casual sharing between PCs. It works best when you have an NFS Server – it should be an “always on” service where the server hosts the files and the clients access them (whereas Samba can work on a more mix-and-match approach where a PC hosts some shares and accesses others remotely). In large computing environments the NFS server will almost certainly do nothing apart from serving files over the network.

Setting up NFS involves installing some additional software and editing a number of configuration files – there’s a good step-by-step guide at https://help.ubuntu.com/community/SettingUpNFSHowTo

4. Use the cloud, Luke

There are a limited number of decent file sharing solutions out there for Linux, and the most important question to answer is what you’re trying to achieve.

As we’ve seen, Samba is great for ad hoc file sharing between PCs, or for serving files in a mixed environment. NFS is ideal for fast, reliable, enterprise class file serving in a Linux/Unix environment (although you can get NFS client software for Windows too, if you really want to).

Neither are great over the Internet though. They’ll just about work over a decently fast VPN (Virtual Private Network) but you’ll feel the pain.

If you want to share files between computers spread across the Internet, you need something different: a cloud solution.

But here again there are important differences in approach (in addition to the differences in implementation where you might decide for or against one product because it doesn’t quite work the way you want it to).

Ubuntu One, for example, starts on the basis that the files you care about are on your computer. It comes bundled with Ubuntu and allows you to sychronize files between not only Ubuntu computers but Windows, Android and Mac. A basic web interface allows you to access the files from any web browser.


All that file copying up and down between the Ubuntu One cloud and all your different devices comes at a price – it can take some time for files to synchronize and things can get out of sync if, for example, there are network issues. Ubuntu One is very useful for one person to access their files on different devices, but less good at sharing files out to multiple users, especially if those people are going to be editing the files.

The alternative is a Google Drive type service. With Google Drive (formerly Google Docs) the “real” copy of the document is always on the Internet, so different people can access (and even edit) the same document at the same time. The benefit is a much more sophisticated system where documents are automatically saved, previous versions can be restored and no shortage of other features.

The downside is that, because the “real” copy is always online, you’re stuck with Google’s editing suite and getting that large document down to your computer could take a while (though Google now allows you to easily share documents of up to 10GB by emailing links).

These are just two of the many file sharing cloud services – it’s a fast-advancing area with new features arriving almost daily to some service or other.

Whatever your needs, Linux offers a file sharing solution for you: it’s just worth taking a bit of time to make sure you get the right one for your needs.

 

 

 

Previous post:

Next post: