Sneakernet, revisited

In case you read my post, Email, the New “Sneakernet”, you might have been left wanting to know more about how to use Samba. There are plenty of sites and books dedicated to the topic, but here’s a quicky post on how to most easily use Samba.

To make your Linux, UNIX or Mac files available to Windows clients, do this:

  1. Make sure you have a reasonably recent version of Samba on your Linux, UNIX or Mac machine. 3.x is generally good; 2.x is not.
  2. Edit or create /etc/samba/smb.conf to look like this:
  3. [global]
    workgroup = WGNAME
    netbios name = MYMACHINE

    [SHARENAME]
    path = /PATHTOSHARE
    public = yes
    guest ok = yes

    Where WGNAME is whatever you want to use as your Windows “workgroup name”, MYMACHINE is your computer’s “netbios” (short, network) name — one that ideally matches your DNS name, SHARENAME is the public name of your “share” (for example, “BobsHomeDir”) and PATHTOSHARE is the file system path that you want to make available as that share (for example, “/home/bob”).

  4. After creating or editing the /etc/samba/smb.conf file, you must start/restart the smbd daemon. Do this with:
  5. /etc/init.d/smbd restart

    (Note: Different versions of UNIX, Linux and Mac OS X do this differently).

  6. To access the files shared in step 2, on your windows machine, type:
  7. net use * \\MYMACHINE\SHARENAME

    Replacing MYMACHINE and SHARENAME as needed.

Doing the reverse, accessing Windows files from Linux/UNIX/Mac is easier. You don’t need to configure anything or run any daemons:

  1. As above, make sure you have a reasonably recent version of Samba.
  2. Run the smbclient program from the command line. It’s arguments look like this:
  3. smbclient -U DOMAIN\\username //WINCOMP/SHARENAME

    Replace DOMAIN and username with the Active Directory short domain name and username of a user that has access to the computer whose files you’re trying to reach . Replace WINCOMP with the name of that computer. You can use its short, Netbios, name or its fully qualified DNS name (e.g. wfsshare or wfsshare.corp.mycompany.com). Replace SHARENAME with the name of the “share” on the Windows computer. Note the use of a double “backslash” when specifying the username and domain. When using the command line shell on Linux/UNIX/Mac, you typically need to type in two backslashes when you want one. The backslash is a special “escape” character and you need two of them to end up with just one. No kidding.

  4. The smbclient program will prompt you for the password of the username that you specified. Type it in.
  5. The program will display a prompt and wait for you to type a command. At this point, pretend you are in ftp. Use the ls command to list available files. Use cd to change remote directories. Use get to retrieve a file. mget is also useful because it supports wildcards. put and mput can be used to copy files from Linux/UNIX/Mac to Windows. Use bye to quit.

There is an alternative to using smbclient. You can use the “smb filesystem”. This approach lets you “mount” a Windows disk into the Linux/UNIX/Mac filesystem so that you can access its files like you would any local file. Here’s how you do that:

  1. Create a “mount point” in your file system. This is where you want your Windows files to appear. On Linux, the media directory is often used for flash drives and other transient “disks”. You might want to use it for this purpose, too:
  2. mkdir /media/fromwindows

    (Replace fromwindows with whatever you want).

  3. Use the mount or mount.cifs command to mount your Windows share to the mount point. I’d try the second form first:
  4. mount.cifs //WINCOMP/SHARENAME /media/fromwindows -o user=USERNAME,password=PASSWORD

    WINCOMP and SHARENAME are as used earlier. USERNAME and PASSWORD are the username and password of a user that has permissions to access the given Windows file share.

  5. If your system complains that it doesn’t know mount.cifs try this instead:
  6. mount -t cifs //WINCOMP/SHARENAME /media/fromwindows -o user=USERNAME,password=PASSWORD

If this doesn’t work, try substituting smbfs for cifs. If that doesn’t work, just email the damned files!