Sharing Files

Sharing Files

Being able to switch back and forth between Linux and Windows or having a GUI that looks similar to Windows is still not enough. As I mentioned, if your data is on an NTFS partition on the local machine, you are pretty much stuck with just reading the data. However, if you data is sitting on a NT server you can access it with no problem.

One of Linux’s strengths is Samba, which provides file and print services using the Session Message Block (SMB) protocol (also called the Common Internet Filesystem-CIFS), which is the same protocol Windows machines use. With Samba, Linux machines can provide the file and print services to any machine that supports SMB, including other Linux machines. In fact, at work we use SMB exclusively to access all of file resources, rather than having to configure NFS as well. That means that no matter what operating system someone is working on, they still have access to the same resources (without any extra administrative effort).

So, if Linux machines can access resources on other Linux machines using SMB, why can’t they access resources on a Windows machine? The answer is: they can.

Samba actually provides two mechanisms to access resources. The first is smbclient, which provides a functionality similar to ftp. That is, you can copy files back and forth, but do not have the level of interactivity that you do when you mount the filesystem.

To solve this problem, Samba also provides smbmount. As it’s name implies smbmount is used to mount filesystems being shared using SMB, and has a syntax similar to the tradition Linux mount command:

smbmount //server/service /mountpoint

Note that the smbmount command is actually a front end to the smbmnt program. Like NFS, smbmount has a number of different options which control not only how the filesystems are mounted, as well as how the client presents itself to the server. For example, you can define the name of your computer, the username used to connect, and so forth. You can also use the -c option to smbmount to pass options directly to the smbmnt command, such as defining which UID and GID to assign to the files on the mounted filesystem.

Let’s look at an example. Assume that you have a share called Data sitting on the server jupiter. There is a user on that machine named jimmo, who has been given access to the share. To connect we might issue a command like this:

smbmount //jupiter/Data /mnt/Data -U jimmo

You are then prompted to input the appropriate password. By using the -N option, you can tell smbmount not to prompt for a password.

One thing to note is that the smbmount command varies between the various distributions. For example, on SuSE Linux 6.2 the above syntax mounts the share as a normal filesystem. However, the same syntax on Red Hat 6.0 behaves like the old smbclient.

Fortunately in all likelihood you will be able to use the standard mount command to access SMB filesystems. Although not configured by default, most current distributions include the smbfs filesystem driver, which allows you to treat SMB filesystems basically like any other filesystem. The syntax to mount the share mentioned previously would be:

mount -t smbfs //jupiter/data /mnt/Data

Note that this syntax only works if the share is set up as public, because you typically don’t need a password.

We go into detail on configuring SAMBA in another section.