Samba Logo

Sharing files: Samba and NFS

Let's say you have a few computers at home. To share files between them, there are two realistic options - Samba and / or Network File System (NFS)

The main difference that between the two is that NFS is a UNIX-based network file system, and Samba was written to allow Linux machines to attach to Windows-based shares. So, with NFS Windows machines aren't going to be able to connect to shared folders on a Linux machine without installing some additonal software. Likewise, Linux machines aren't going to connect to shared folders on a Windows machine without having Samba installed.


The Samba method

Samba is well supported in most modern Linux distributions, so this is most likely to be your preferred method. Samba allows Linux machines to share folders and printers with Windows machines using the SMB protocol (Server Message Block) or CIFS (Common Internet File System). CIFS is similar to SMB but has additional features.

Install everything you need for Samba

Debian:

apt-get install samba smbclient smbfs swat

Fedora:

yum install samba samba-client samba-common samba-swat xinetd

The packages called samba and smbclient should definitely be installed for maximum functionality. The swat (and xinetd for Fedora) packages allow you to use SWAT, which is a web-based configuration tool, and is probably the easiest way to start configuring Samba if you don't know your way around the configuration files.

Create samba users on server

smbpasswd -a user
smbpasswd -a user2

This part is pretty obvious... in the default mode (that is, if you aren't using something more complicated like a central server with LDAP) is that Samba users and passwords are stored locally on the machine. This means that you have to setup Samba users and passwords to allow users to access shares on your server. These passwords should be the same as the user's ordinary passwords if possible - this will simplify matters...

Use the following to allow CIFS user mounts

chmod +s /sbin/mount.cifs
chmod +s /sbin/umount.cifs

You'll need to run the above commands as root if you want users to be able to mount CIFS shares without super-user priviledges. CIFS has more capabilites than smbfs, so it is recommended that you create shares using the "-t cifs" parameter as shown below.

View samba shares

smbclient -NL server.local

The "N" part of the "-NL" switch above means do not attempt to login as a user, i.e. use guest mode. The "L" part of the "-NL" switch means list shares.

To mount / unmount CIFS share as a user

/sbin/mount.cifs //server.local/Storage /home/user/Mount
/sbin/umount.cifs /home/user/Mount

Once you know what shares are available, you probably want to mount them. While it's entirely possible to mount shares using Nautilus or another utility, we're covering the basics of mounting shares via the terminal here, but use whatever works best for you.

I've found that I need to use "machinename.local" to communicate with other machines on the network, as opposed to just "machinename". Try pinging the IP address of another machine on the network to establish it is up and running, then try it by its hostname to find out whether you need to add ".local" on your network. On Fedora, you may need to install the nss-mdns package to get this functionality.

Examples of how to mount / unmount shares as root

mount -t cifs //server.local/Storage /home/user/Mount
mount -t smbfs //server.local/Storage /home/user/Mount
mount -t cifs //server.local/Storage /home/user/Mount -o \
username=USER,password=PASSWORD,domain=DOMAIN
umount /home/user/Mount

From top to bottom: a simple cifs mount, a simple smbfs mount, a more complex cifs mount with user / domain details, and a simple unmount. All of the above will probably require super-user access.

Modify samba settings using SWAT

Ensure xinetd is installed and started if you're using Fedora (Debian seems happier using openbsd-inetd which is installed by default I think), open a browser and go to:

http://127.0.0.1:901

To login, use the username of "root" and the super-user password. You can find more information on SWAT here.

View a list of existing Samba users using a terminal

cat /etc/samba/smbpasswd | cut -f1 -d ":"

This is useful for determining whether users have been setup when connected to a server via SSH.


The NFS method

NFS is most likely installed already if you have a Linux system, but any Windows machines you want to be able to connect to your shares will need an addon installed from the Microsoft website called Windows Services for UNIX.

Connecting to a server with SSH and creating a share by editing /etc/exports

This isn't actually to do with NFS, but being able to connect into your server via SSH is probably something you should have a go at, at least once. In this case, we are going to create a share by editing the /etc/exports file.

ssh user@server.local
nano /etc/exports

Add the following line to the end of the /etc/exports file:

/media/Storage 192.168.0.1/255.255.255.0(ro)

This creates a share from /media/Storage, and makes it accessible to any machine on the local network (assuming your network is on the 192.168.0.x range). The "(ro)" mean the share is read only.

Save the file and restart the NFS service:

Debian:

/etc/init.d/nfs-kernel-server restart

Fedora:

service nfs restart

Mounting / unmounting an NFS share

mount -t nfs server.local:/media/Storage /home/user/Mount
umount /home/user/Mount

We use the "-t nfs" switch to let mount know we are creating an NFS mount. The format is slightly different to the Samba format above - notice the ":/" in the above command. Also note that we need to specify the full path to the share, as if we were on the server itself. With Samba, we just pointed at the share.

We could also mount as a user by doing:

/sbin/mount.nfs server.local:/media/Storage /home/user/Mount

...as long as there is a match for /home/user/Mount found in /etc/fstab

NFS on Windows XP (including XP Home)

To enable support for NFS, you will need to download and install "Windows Services for UNIX Version 3.5" from here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=896c9688-601b-44f1-81a4-02878ff11778

This should be sufficient on XP Professional, you should be able to map a network drive to the shared folder via Windows Explorer. However, the installer will not work on XP Home without some slight modification...

The following is adapted from the instructions found on this website:

http://oreilly.com/pub/h/2883

Extract the SFU35SEL_EN.exe file (you should be able to do this with File Roller, but failing that, 7zip can also extract executable files).

Install a hex editor, e.g.

Debian:

apt-get install ghex

Fedora:

yum install ghex

Make a backup of "SfuSetup.msi":

cp SfuSetup.msi SfuSetup.msi.backup

Load the file "SfuSetup.msi" in the hex editor.

Select Find > "VersionNT = 501"

Check string reads: "NOT (VersionNT = 501 AND MsiNTSuitePersonal)"

Change 501 to 510 by overtyping the "01" with "10" in the right-hand pane.

Save the file.

You should now be able to install the program on an XP Home machine and access NFS shares.