Using Samba to Share Your Linux Folders with Another PC or Virtual Machine

Print
by Rob Williams on April 15, 2014 in Software

Creating a network share on Linux is quite a bit different than on Windows, but that doesn’t mean that it requires a degree from Tux U. In this article, we take a look at installing and configuring Samba, creating some shares, and then accessing those shares across a variety of platforms.

Page 2 – Taking Advantage of Our Samba Shares

Once a Samba share is created, it can be accessed through applications that support the SMB protocol, as one would expect. While Samba’s big focus is Windows, it’s not the only piece of software that can take advantage of it. Many file managers for mobile platforms are designed to support the protocol, and other Linux PCs can mount them as well.

On this page, we’ll take a look at a couple of different solutions for accessing our Samba shares.

First things first: The Microsoft side. In Windows, browsing to “Network” should reveal your Linux PC’s hostname; in my particular case, it’s TGGENTOO. After double-clicking on it, the entire list of shares will be revealed.

Browsing a Samba Domain in Windows

Network shares are all fine and good, but it’s a hassle that to get to one, it requires a bunch of clicking and waiting. Depending on Windows’ mood, the Linux hostname might not even appear on the network. To ease the pain of having to go through all that again, mounting a share from within Windows is a great option. For simple needs, a desktop shortcut might provide quick enough access, but shortcuts by design are quite limited. When mounting a network share as a Windows network drive, however, it acts just as a normal hard drive does.

Mounting a Samba share as a network drive is simple:

net use X: \\HOSTNAME\Share
net use X: “\\HOSTNAME\Share Name”

Quotation marks surrounding the entire share is required if there’s a space in its name.

A real-world example:

Creating a Network Drive on Windows

See? It couldn’t be more simple.

Using a Samba Share in a Virtual Machine

In the title of this article, I reference virtual machines; but why? Guest OSes should be no different when it comes to mounting a network share, right? What’s the big deal? For me, it’s a very big deal, given I use a PC that dual-boots Linux and Windows. It might be best to just provide a screenshot, then explain it:

Windows VM Using Linux Shares via Samba

That’s a screenshot of Windows 7 that I run inside of a virtual machine when I’m in Linux. Because I’ve mapped my Samba shares to the same drive letters as in native Windows, this virtualized OS reads files from many of the same locations. Steam, for example, reads my games from the F:\ drive in both native and VM Windows, which means I could easily play simpler Windows games while in Linux all while using the exact same library.

Another example is with uTorrent. In this virtualized Windows, I have the locations of the torrents stored on the same drive letters, and likewise, I am running the exact same uTorrent install between OSes. What that means is, I could delete or add a torrent inside this VM, and the change would be reflected when I return to native Windows.

Using a Samba Share on a Mobile Device

It might be hard for some to appreciate the above, so let’s get back onto less complicated things. Here’s me browsing all of my Samba shares through ES File Explorer on Android:

Connecting to Samba Shares on Android

Some file managers on mobile are not that feature-rich, so complications might arise if accessing a share that has differing user / password requirements for different shares. If everything is wide-open, as it is with my setup, you should have a trouble-free experience.

Using a Samba Share on Linux

In some cases, Linux file managers might show Samba shares right alongside regular folders in its left pane; at that point, it’d just be a matter of clicking on one to access it. If not, or fine-tuned mountpoints are desired, you can mount the share like any other device:

mount -t cifs -o username=username //HOSTNAME/Share /mnt/location

Using this command will provide a prompt to enter a password; this can be avoided by modifying the command to username=username,password=password (not great for security reasons).

I recommend mounting the network share this way before inputting it into /etc/fstab, just to make sure all is well. Afterwards, your system’s fstab file can be edited as sudo (or su) to automatically mount a share at boot.

Adding values for a network share to fstab isn’t complicated, but making sure they’re the correct values can be. Depending on the network, the required hostname might have to be the text value (TGGENTOO), or an IP address (192.168.1.100). Some trial and error can be expected, and at worst, a trip to your distro’s website might have to be taken.

Here are two examples of what could go into an fstab:

//192.168.1.100/Storage /mnt/nas-storage cifs username=guest,uid=1000,iocharset=utf8 0 0
//TGGENTOO/Storage /mnt/nasstore cifs username=guest,uid=1000,iocharset=utf8 0 0

If a given configuration proves problematic, make sure that the Samba share can be mounted outside of fstab, with the mount command (as seen above). Once a share is properly mounted that way, it should be a breeze translating it into fstab speak.

Final Thoughts

At this point, I hope that you’ve successfully configured Samba to your liking, and are able to access the shares from all of your devices. If not, I’d recommend perusing your distro’s website for a Samba guide, and make sure that all of the directions were followed to a T. Sometimes, errors can be caused by the simplest thing, and that thing might not apply to all distros.

Samba Logo

Past that, it’d be a good idea to hit-up a search engine and query the error or problem with your distro’s name attached to it. I have done a lot of troubleshooting with Samba and other Linux tools across multiple distros, and that’s how it’s been proven to me that not all distros are alike. Fixing one issue in Gentoo is far different than fixing the same kind of issue in Linux Mint – at least sometimes.

In the worst case, leave a comment here and we’ll try our best to help.

Maybe it’s not trouble you’ve run into; instead, it’s absolute disgust at the fact that I left out some glaring detail. If that’s the case, I encourage you to also leave a comment. I’d love for this article to remain relevant, so if I’ve missed something important, it should be added in.

This article began as a mere news post, and it became this. I think it’s time for a game. Perhaps Samba de Amigo? *shake shake*

Support our efforts! With ad revenue at an all-time low for written websites, we're relying more than ever on reader support to help us continue putting so much effort into this type of content. You can support us by becoming a Patron, or by using our Amazon shopping affiliate links listed through our articles. Thanks for your support!

Rob Williams

Rob founded Techgage in 2005 to be an 'Advocate of the consumer', focusing on fair reviews and keeping people apprised of news in the tech world. Catering to both enthusiasts and businesses alike; from desktop gaming to professional workstations, and all the supporting software.

twitter icon facebook icon instagram icon