Article Figure 1 Figure 2 Figure 3 Figure 4
Figure 5 Figure 6 nov2006.tar

Accessing Windows Resources from a Linux Desktop

Marcel Gagné

You're one of the lucky ones. Despite incredible pressures, you've somehow managed to convince your boss to let you run Linux on your workstations instead of Windows. It could be that you've already saved your organization tens of thousands of dollars by convincing them to upgrade to OpenOffice.org instead of the latest Microsoft Office, and now the company is willing to explore other possibilities. However, you are still going to have to deal with the Windows workgroup or domain and the appropriate shared files and printers.

It used to be called the network neighborhood. On Windows XP machines, it's called network places. You may now be running a Linux desktop, but there are many important files shared from the XP machine over in accounting, files that are shared in the network neighborhood. Files you need to work with. Ironically, some of those Windows file servers may in fact be Linux servers running Samba, seamlessly providing network drives to Windows desktops inside your company.

Samba on Linux does a great job of providing the same file and printer sharing that Windows servers used to and sometimes still do provide, so it should not be surprising that Samba client software tends to come as part of the standard installation on most modern Linux distributions. This means you can connect to a Windows share on the network using the smbclient program, like this:

smbclient -L lex 
            
This would produce a report of shares that looks something like the following:

Domain=[LEX] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager] 

      Sharename    Type      Comment 
      ---------    ----      ------- 
      Reports      Disk 
      IPC$         IPC       Remote IPC 
      print$       Disk      Printer Drivers 
      SharedDocs   Disk      
      Printer2     Printer   Microsoft Office Document Image Writer 
      LEX_C        Disk 
      ML-1710      Printer   Samsung ML-1710 Series
Assuming that you had the permissions to view the Reports folder, you could connect to it like this:

smbclient //lex/Reports -U winuser 
In the above example, I am connecting to a Windows XP box from my Linux workstation as user "winuser". The system will then ask me for a password, after which I will be at a Samba prompt that looks like this:

Domain=[LEX] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager] 
smb: \>
    
From here, type help, and smbclient will offer up a list of all the things you can do while connected via the commands at your disposal. A number of them are obvious such as dir, copy, and so on. While this is all good, it's not pretty in the graphical sense, and you can't use this while working in your graphical file managers or inside OpenOffice.org's applications.

Graphical Clients You Already Have

There's a Swiss army knife approach to a number of Linux tools, with tons of useful tools folded out of the way, waiting to be discovered. It's easy to pass by those friendly, everyday programs, never thinking that they might well be all you need to get the job done. This is true regardless of whether you run KDE or GNOME as your desktop environment. Let's start with the KDE side of things and look at how you would access this machine using Konqueror. Open up Konqueror (either as file manager or browser) and type the following in the Location field:

smb:/ 
Samba servers or Windows machines advertising network shares will first appear in the browser window under their workgroup name (e.g., ACCOUNTING, RESEARCH, etc). Take a look at Figure 1 and you'll see a Konqueror session with a two-panel view (click Window on the menu bar and select Split View, Left/Right -- alternatively, you can press Shift+Ctrl+L). In the left panel is the basic network browser view with three active workgroups. In the right-hand panel, I've clicked on the DARKSIDE workgroup to show the computer(s) that make up part of that group.

To read, write, or otherwise make use of the files shared on those computers, double-click on the corresponding folder for that computer -- the computer named Lex, for instance. All of the available shared directories (or folders) on that system are then visible (see Figure 2). You can then navigate those folders as you would any other folder visible in Konqueror. That said, you may also see shares to which you don't necessarily have access. Clicking (or double-clicking, depending on your configuration) on them will bring up an authentication dialog asking you for a user name and password.

From here, it's all classic drag and drop, graphical file manager browsing. You can go inside whatever folder you have access to, locate the appropriate document, and open it with OpenOffice.org Writer. Right-click on the file, select Open with, and just like that, you are editing a document on a shared Windows resource.

Ideally, we don't want to go through this whole navigation process each and every time. To bring a given network share a few clicks closer, simply bookmark the appropriate shared folder. Click Bookmark on Konqueror's menu bar, then select Add Bookmark.

Over on the GNOME side of things, we have Nautilus. You will find the process very similar to what we just did with Konqueror. Start Nautilus, press Ctrl+L to open the location bar, and then type the following:

smb:/// 
    
On a GNOME desktop, such as my Ubuntu system here, you can also click Places on the top panel, and select Network Servers. When the file browser window appears, double-click on Windows Network. Nautilus will then display the active workgroups on the network (see Figure 3).

From there, you can double-click on one of the workgroups to select a computer. Then, from the list of computers, double-click on your choice and you can browse the individual resources offered (see Figure 4). Again, be aware that while you move around from computer to computer like this, you may occasionally be asked for a user name and password for that computer or even the specific folder.

As with the Konqueror example before this, you can save yourself a little time by bookmarking the folder of your choice. The only problem with both of the suggestions I've made so far is that neither of them lets you permanently mount network drives. Mounting a drive is easy, but it's not quite the point-and-click ease that Windows users on your network have access to.

Smb4K for Power Users

Konqueror and Nautilus are fine for a great number of applications and, depending on your needs, they might be all that you require. For a more robust and flexible means of working in and with the network neighborhood (or network places), you simply must take a look at Smb4K, a super-classy SMB browser tool that is also flexible and powerful. Furthermore, it makes it possible to preview shares, mount shares locally, disconnect (or unmount) shares when you log out, reconnect shares automatically on startup, and more. You can get Smb4K from the application's Web site at:

http://smb4k.berlios.de 
    
Smb4K is an excellent and very capable package, definitely worth the time to investigate. Binary packages for Debian, SUSE, and Fedora are available on contrib sites for various distributions (as I write this, I'm installing it on an Ubuntu system using Synaptic). The main Smb4K site also has the full source code available for download.

When you have installed the package, run the program by calling smb4k. As soon as you start Smb4K, it scans the network looking for active shares. You can fine-tune the functionality and options, including such things as whether you want shares to be automatically reconnected by clicking on Settings in the menu bar and selecting Configure Smb4K. The graphical interface is intuitive and easy to navigate and the package is easy to use.

The display is divided into a left-hand navigation panel where workgroups, computers, and shares can be listed and navigated. To mount a share, right-click on it and select Mount. If you would rather see what you are getting into first, choose Preview instead.

Mounted drives appear in the top right-hand window as drive icons. Clicking on one of the drive icons opens up a Konqueror window to that particular share. The Network tab provides information about the connected host. Click the Share tab and you'll get further details including the size of the network drive, its current use, and its contents.

If you run the df from the command line, you'll see that the drives are now mounted for your use in your own home directory under an smb4k directory prefix. For instance, in the example in Figure 5, the listing looks like this:

Filesystem              Size  Used Avail Use% Mounted on 
//SCIGATE/Finance_Data  5.9G  5.3G  569M  91% /home/mgagne/smb4k/ \       
                                              SCIGATE/Finance Data 
//LEX/LEX_C             25G   20G   5.1G  80% /home/mgagne/smb4k/ \
                                              LEX/LEX_C 
    
The path used by Smb4K to mount the shares is one of the many things that can be changed through the configuration dialog. Click Settings on the menu bar, then select Configure Smb4K. A window will appear with a large work area to the right, and a vertical sidebar of configuration categories to the left (see Figure 6).

Just modify the directory path, then click Apply or OK to exit. Before you exit, however, take a moment to explore some of the additional settings here. Under the same Shares category, there are options for remounting shares when you log in, and unmounting those shares when you log out. This is not the default behavior but you may, like me, find this to be the obvious and most useful way to do things.

Time for a Backyard BBQ?

As you can see, there's no great magic in accessing Windows network shares using a modern Linux desktop. For casual use, the standard desktop file browser -- whether it be Konqueror or Nautilus -- may be all you need. Smb4K, on the other hand, will take care of the rest for the most demanding of users.

Even though you are surrounded by people running on Windows workstations, you're lucky enough to be using a Linux desktop. That doesn't mean you can't be part of the neighborhood. With the right tools, everyone will be feeling downright neighborly. Better make sure you've got lots of burgers.

Marcel Gagné is an award-winning writer living in Mississauga, Ontario. He is the author of the all new Moving to Ubuntu Linux, his fifth book from Addison Wesley. He also makes regular television appearances as Call for Help's Linux guy. Marcel is also a pilot, a past Top-40 disc jockey, writes science fiction and fantasy, and folds a mean Origami T-Rex. He can be reached via email at: mggagne@salmar.com. You can discover lots of other things from his Web site at: http://www.marcelgagne.com/.