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:
- 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.
- Edit or create /etc/samba/smb.conf to look like this:
- After creating or editing the /etc/samba/smb.conf file, you must start/restart the smbd daemon. Do this with:
- To access the files shared in step 2, on your windows machine, type:
[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”).
/etc/init.d/smbd restart
(Note: Different versions of UNIX, Linux and Mac OS X do this differently).
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:
- As above, make sure you have a reasonably recent version of Samba.
- Run the smbclient program from the command line. It’s arguments look like this:
- The smbclient program will prompt you for the password of the username that you specified. Type it in.
- 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.
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.
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:
- 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:
- Use the mount or mount.cifs command to mount your Windows share to the mount point. I’d try the second form first:
- If your system complains that it doesn’t know mount.cifs try this instead:
mkdir /media/fromwindows
(Replace fromwindows with whatever you want).
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.
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!