Every year, Linux journalists and fans openly ponder whether the new year will be the year of the "Linux desktop." Although it's easier than ever to buy a new machine that runs Linux out of the box or migrate an existing Windows system to Linux, simply installing and booting Linux isn't the final step in making it your daily driver operating system. You may have switched to using Linux on your desktop, but the environment in which you use your new Linux system may not be as modern. Most enterprise, small-to-medium business, and small office/home office environments have Windows-related requirements you must consider. You may also need to use hardware with your Linux system that is only actively supported on a Windows platforms. Luckily, a variety of solutions to these issues exist.
Accessing shared Windows file systems
Access to shared Windows file systems is probably the most common business requirement for Linux system users. Many businesses still use Windows as the core of the infrastructure to support enterprise mail and calendaring systems, such as Microsoft Exchange Server, and for simple file and data sharing through exported file systems, generically known as Windows shares.
Linux provides multiple ways to access Windows shares. The mechanism you choose depends on the frequency with which you need to access data on a Windows share and whether the Linux system you are configuring is a personal, single-user system or one that multiple users share.
Accessing Windows shares from the command line
The Samba Project (see Resources) is an open source project that enables Linux, UNIX, and other UNIX-like operating systems to interoperate with Windows. Samba is available in the repositories for most Linux distributions and is generally installed and configured to enable a Linux system to join and interoperate with an existing Windows workgroup or domain, often serving as a Common Internet File System (CIFS) file server that Windows systems can use. Samba 4.x installations also let a Samba server act as an Active Directory Domain Services controller and integrated Domain Name System for a Windows domain.
Although a Samba server provides an excellent mechanism for making Linux
resources available from Windows systems and enabling Linux systems to
print to Windows printers, installing and configuring a Samba server is
overkill if all you are interested in is occasionally retrieving files
from a Windows share. The Samba client package
samba-client) contains several utilities
designed for such occasional interaction, including the
smbclient application, which provides an
interactive command-line interface (CLI) to remote Windows shares.
If you're not sure of the names of the shares available on a remote Windows
server, you can use the
to query a server and list the resources available on it by typing the
-L option followed by the name or IP address of
the server, as shown in Listing 1.
Listing 1. Using
smbclient to list Windows server resources
$ smbclient -L win2008server Enter wvh's password: Domain=[WORDSMITHS] OS=[Windows (R) Small Business Server 2008 6001 Service Pack 1] Server=[Windows (R) Small Business Server 2008 6.0] Sharename Type Comment --------- ---- ------- Address Disk "Access to address objects" ADMIN$ Disk Remote Admin Brother HL-2070N Printer Brother HL-2070N C$ Disk Default share ExchangeOAB Disk OAB Distribution share IPC$ IPC Remote IPC NETLOGON Disk Logon server share print$ Disk Printer Drivers Public Disk RedirectedFolders Disk Resources$ Disk "Event logging files" SYSVOL Disk Logon server share [...]
As shown, the
smbclient application uses the
current Linux user as the user to authenticate as on the remote Windows
server and prompts for that user's password to access the remote server.
If your login is different on the Windows server, you can use the
-U option to specify the login to use.
After you have identified the name of the share you want to connect to, you
can use the
smbclient application to connect to
a specific share to examine or retrieve files, as shown in Listing 2.
Listing 2. Using
smbclient to retrieve files from a Windows share
$ smbclient //win2008server/Public Enter wvh's password: Domain=[WORDSMITHS] OS=[Windows (R) Small Business Server 2008 6001 Service Pack 1] Server=[Windows (R) Small Business Server 2008 6.0] smb: \> cd Software\Linux smb: \Software\Linux\> ls . D 0 Sun Jan 27 23:40:42 2013 .. D 0 Sun Jan 27 23:40:42 2013 acl82express-linux-x86.bz2 A 44960643 Sun Jan 27 23:40:24 2013 alien_8.87.tar.gz A 64336 Sun Jan 27 23:39:24 2013 crossover-12.1.0-1.i386.rpm A 47233108 Sun Jan 27 23:39:14 2013 [...] 59997 blocks of size 1048576. 32474 blocks available smb: \Software\Linux\> get softmaker-office-2012-674.x86_64.rpm getting file \Software\Linux\softmaker-office-2012-674.x86_64.rpm \ of size 147058656 as softmaker-office-2012-674.x86_64.rpm \ (16345.5 KiloBytes/sec) (average 16345.5 KiloBytes/sec) smb: \Software\Linux\> quit
The example in Listing 2 shows that
smbclient provides a CLI to the remote server.
This interface supports familiar Linux commands such as
cd (for moving around in the directories on the
remote server) and
ls (for listing the contents
of a given directory). When you have located a file that you want to
retrieve, you can use the
get command to
retrieve that file, storing it in the directory from which you executed
smbclient. To store a retrieved file in another
directory, you can use the
lcd (local change
directory) command to change the directory that
smbclient views as the current directory.
smbclient application is fine if you
need only occasional access to one or more files in a Windows share and
don't care about using a file manager such as Gigolo, GNOME Nautilus, KDE
Dolphin, Konqueror, or Thunar to graphically browse a Windows share. The
smbclient application makes a remote share
available within the context of that application, not to your system as a
whole. To browse a Windows share and make it available to the applications
of your choice, you will have to mount that share on your system in the
same way local file systems are mounted.
Permanently mounting Windows shares
You can manually mount a Windows share on a directory on your system by
mount command as the root user or by
sudo application, as shown in Listing 3. The
option and its
cifs argument specify the type
of file system you are mounting and, in this case, causes the generic
mount command to invoke the
/bin/mount.cifs command. Use your system's
package-management commands to install the
cifs-utils package, which is part of the Samba
Listing 3. Mounting and listing a manually mounted Windows share
# mkdir /mnt/PUBLIC # mount -t cifs //winserver2008/Public /mnt/PUBLIC Password: # ls -l /mnt/PUBLIC total 1 drwxr-xr-x. 1 root root 0 Jan 27 16:19 Desktop -rwxr-xr-x. 1 root root 174 Jan 19 2008 desktop.ini drwxr-xr-x. 1 root root 0 Jan 19 2008 Documents drwxr-xr-x. 1 root root 0 Jan 27 23:38 Downloads drwxr-xr-x. 1 root root 0 Jan 19 2008 Favorites drwxr-xr-x. 1 root root 0 Jan 19 2008 Music drwxr-xr-x. 1 root root 0 Jan 19 2008 Pictures drwxr-xr-x. 1 root root 0 Jan 27 23:37 Software drwxr-xr-x. 1 root root 0 Jan 19 2008 Videos
mount command in Listing 3 makes the remote share available through the
/mnt/PUBLIC directory, but has a few shortcomings:
- You cannot simply add this command to your /etc/fstab file to
automatically mount the share because you are prompted for a password
after executing the
mountcommand. Unless you identify a specific user to authenticate as, you must supply the remote Windows password for the user you executed the
- Executing the
mountcommand as the root user mounts the share as being owned by the root user. Although mounting a share in this fashion is fine if you only want to read files in that share, you can only write to the mounted share as the root user, which is usually inconvenient.
To resolve these problems, you can specify special, CIFS-related options
when executing the
mount command to mount a
CIFS share. These options are:
username=<login>- Specifies the user that you will use to authenticate to the remote share. You can abbreviate this option to
password=<login>- Specifies the password for the user who will authenticate to the remote share (the user you specified as the user that you will use).
uid=<UID>- Specifies the user ID (UID) of the user who will own the files and directories in the mounted share. If you are using password file authentication on your Linux desktop, find your UID by using the
grepcommand to search for your login in the system's password file, as shown in the following example.
$ grep wvh /etc/passwd wvh:x:500:500:William von Hagen:/home/wvh:/bin/bash
The UID is the third field in a password file entry — in this case, efficiently500.
gid=<GID>- Specifies the group ID (GID) of the user who will own the files and directories in the mounted share. If you are using password file authentication on your Linux desktop, find your GID by using the
grepcommand to search for your login in the system's password file. The GID is the fourth field in a password file entry, as shown in the example in the previous bullet.
mount command using these options,
broken across two lines for formatting purposes, is as follows:
# mount -t cifs -o username=wvh,password=MYPASSWORD,uid=500,gid=500 \ //win2008server/Public /mnt/PUBLIC
You can use a command like this one from the CLI or add a similar entry to
your /etc/fstab file to automatically mount the file system whenever you
boot your system. The following is an equivalent /etc/fstab file entry to
//win2008server/Public /mnt/PUBLIC cifs \ username=wvh,password=MYPASSWORD,uid=500,gid=500 0 0
This command would appear as a single line in your /etc/fstab file and is
broken across lines in this example for formatting purposes.
Unfortunately, this command has some obvious security problems because you
must expose your password in the /etc/fstab entry and the file /etc/fstab
is typically readable by every user on the system. To resolve this
problem, put your user name and password in a text file that you identify
credentials mount option. For
//win2008server/Public /mnt/PUBLIC cifs \ credentials=/etc/cred.wvh,uid=500,gid=500 0 0
The format of a credentials file is as follows:
You can then make the /etc/cred.wvh file readable only by the root user (as
mount command must be executed) using
the following command:
# chmod 600 /etc/cred.wvh
credentials mount option provides a
nice balance between having to specify a user name and password each time
you mount a file system and not exposing that information to everyone who
has access to your system.
Mounting Windows shares on demand using sudo
If you only want to occasionally mount a share, you could add the
noauto option to the list of mount options
shown in the examples in the previous section. This option prevents the
specified Windows share from being mounted automatically each time you
restart your system. You would then have to mount the share from the
command line whenever you wanted to access files in that share.
You must always execute the
mount command as the
root user, which usually means that anyone who wants to mount that share
must know the root password on the system. If you do not want to
automatically mount the share each time you restart your system and want
to limit the people who need to know the root password (or simply limit
the number of times you have to use that command), you can enable a
regular user to mount the share using the
command. To do so, use the
visudo command to
edit the /etc/sudoers file, adding an entry like the following to the end
of the /etc/sudoers file.
wvh ALL=/bin/mount /mnt/PUBLIC, /bin/umount /mnt/PUBLIC
This entry enables the user wvh to execute the
/bin/mount /mnt/PUBLIC and
/bin/umount /mnt/PUBLIC commands using the
sudo command but does not enable that user to
umount commands to mount or unmount any other
file systems. If you want all users on a given system to be able to mount
and umount the /mnt/PUBLIC share, you could replace the user name
wvh with the generic
%users expression. In that case, make sure that
the files that users might want to update are writable by the group
identified by the
anongid identified in the
associated /etc/fstab entry and that all users belong to this group.
Note: Another approach to mounting Windows shares is to
use one of the File system in User Space (FUSE) packages that support CIFS
file systems. The
fusesmb packages are fairly popular but have
not been updated in a while and require substantial configuration to make
them work properly. (See Resources for links to
Working with Windows text files on Linux systems
Most people think of text files as a standard type of file that is the same
on every computer system and can therefore be safely used for
configuration files, quick notes that you can read on any operating
system, and so on. Unfortunately, that's not the way it is. Although the
same character sets are used for text files on Windows and Linux systems,
the characters used to identify the end of a line of text differ. Windows
and DOS systems mark the end of a line of text with two characters: a
carriage return (Ctrl-M) and a line feed (Ctrl-J). Linux and all UNIX-like
systems mark the end of a line of text with a single character: the line
feed character. If you use a Linux utility to open a text file that was
created on a Windows system, you will see a Ctrl-M character at the end of
each line, often displayed as
\r. This extra character can confuse Linux
utilities that need to read such files.
Linux provides two commands that enable you to automatically change the
end-of-line characters in a text file. The
dos2unix command, which is available for most
Linux distributions in a package by the same name, automatically converts
text files that were created in Windows (or DOS) to use the Linux and UNIX
conventions to mark the end of a line of text, stripping out all of the
Ctrl-M characters. An equivalent program,
unix2dos, is available in a package of the same
name to convert Linux and UNIX text files to Windows-format text files.
If you are a fan of the Emacs text editor, you can add the Emacs commands
shown in Listing 4 to your
Emacs configuration file (~/.emacs). You will then be able to execute the
unix-file commands to convert the contexts
of a text buffer to the text file format specified in the name of the
Listing 4. Emacs commands for changing text file types
; ; Functions for changing buffer modes ; (defun dos-file () "Change the current buffer to Latin 1 with DOS line-ends." (interactive) (set-buffer-file-coding-system 'iso-latin-1-dos t)) (defun mac-file () "Change the current buffer to Latin 1 with Mac line-ends." (interactive) (set-buffer-file-coding-system 'iso-latin-1-mac t)) (defun unix-file () "Change the current buffer to Latin 1 with Unix line-ends." (interactive) (set-buffer-file-coding-system 'iso-latin-1-unix t))
Note: The sample Emacs commands shown in Listing 4 assume that you are using the Latin 1 character set. If you are using another character set in your text files, you will need to modify these commands to reflect that character set.
Using network devices that were designed for Windows
Although Linux provides the software that most people need to use on their computers, keeping up with the latest network hardware is a problem for any operating system. Modern Linux distributions include device drivers for an impressive range of network hardware, but Linux drivers for new network protocols and related hardware can lag behind, especially in the wireless space. If your Linux machine cannot recognize or use a new network device when the system boots, the drivers for that device are not available or some other resource that the device drivers require, such as hardware-specific firmware, was not available. In such cases, your friendly neighborhood search engine should always be your first resort: Someone else with the same newly released hardware may already have gotten it working on a Linux system. (See Resources for links to multiple sites that provide information about hardware that Linux supports and people's experiences with that hardware.)
If you can't find built-in Linux drivers for a newly released piece of network hardware, most new hardware ships with a CD that contains special drivers that enable supported operating systems to efficiently use that hardware. Unfortunately, these driver CDs rarely include drivers that are specifically designed for Linux systems. In some cases, Linux drivers for specific hardware are available from the hardware vendor's website. If this is the case, the vendor usually provides installation and configuration instructions as well. Many hardware vendors also provide online forums on which you can ask questions and discuss any installation or configuration problems you're having.
If the Linux distribution that you're using or experimenting with doesn't
include support for a specific piece of network hardware that is in your
desktop or laptop computer and the vendor does not provide Linux drivers,
all is not lost. The
enables you to use most Windows XP network device drivers on your Linux
system. The Network Driver Interface Specification (NDIS) is a standard
application programming interface for network interface cards (NICs). The
NDISwrapper package does not support NDIS,
Version 6, which is the driver format that Windows 8, Windows 7, and
Windows Vista use, so you will only be able to use the
NDISwrapper package with Windows XP drivers. If
you are using a 64-bit Linux system, you can only use 64-bit Windows XP
drivers; 32-bit Windows XP drivers will not work on a 64-bit system.
After installing the
(which may also install the
package on some Linux distributions) on your system, you can install and
use a Windows XP NDIS driver by performing the following steps:
- Check whether any Linux driver for the same hardware is already
loaded, and, if so, unload it using the
- Locate the .inf and .sys files for the driver you want to use.
If the Windows XP drivers for your hardware are provided in a self-extracting .exe file, you can usually extract them using the Linux
unziputility. If they are provided in a .cab file, you can extract them using the Linux
cabextractutility. If they are provided in InstallShield files, you can extract them using the
unshieldutility. (All of these utilities are in packages by the same name in the repositories for most Linux distributions.) Worst case, you can install the drivers on a Windows machine, and then copy them to your Linux system.
- Install the driver using a command like the following as the root user
or by using the
ndiswrapper -i DRIVER.inf
- Verify that the Windows driver is installed correctly by running the
following command as the root user or by using the
- Load the
NDISwrapperloadable kernel module by running the following command as the root user or by using the
- Create a module configuration file alias for your network interface by
running the following command as the root user or by using the
This entry will look something like the following:
alias wlan0 ndiswrapper
Make sure the name of the Ethernet interface with which the
ndiswrapperkernel module is associated matches the interface that you want to use it with, as shown in the output of a command like
At this point, your new network hardware should be visible from your Linux
system, and you should be able to use standard Linux network configuration
utilities such as
/sbin/ifconfig or configure
and use the associated NIC.
If you want to use the
ndiswrapper kernel module
and a Windows driver for hardware that also has a native Linux driver, you
will want to create a file called something like
/etc/modprobe.d/blacklist-DRIVER.conf that contains
an entry like
blacklist DRIVER to ensure that
the Linux driver is not loaded the next time you restart your system.
If you prefer the simplicity of a graphical application, multiple options
are available for the
Figure 1 shows the
ndisgtk application, which you can install on
your system from the package of the same name.
Figure 1. Adding a Windows driver using ndisgtk
NDISwrapper package is both useful and
impressive. Even if Linux provides native drivers for your hardware, you
may find that using the Windows drivers can provide better performance
than using the built-in Linux equivalents.
Linux is a powerful operating system that is free and — nowadays — also easy to use. Using Linux on your desktop or portable computer can provide substantially better performance than operating systems such as Windows and is also a great way to give new life to older computers. However, interoperating with Windows-based servers, certain types of Windows files, or Windows-oriented network hardware is still a requirement in many business and home environments. Linux provides a wide selection of software and techniques that enable you to interoperate with such systems and hardware, giving you the best of both worlds from your desktop Linux system.
- The Samba Project provides a suite of Windows interoperability applications for Linux, UNIX, and UNIX-like operating systems.
- The developerWorks exam-preparation series of articles for Linux Professional Institute-302 certification includes multiple sections on Samba that provide an excellent introduction to installing, configuring, and using Samba.
- The Linux Hardware Compatibility List provides links to lists of hardware know to work well with specific Linux distributions; lists of printers, scanners, video cards, audio hardware; digital cameras known to work well with Linux in general; and much more.
- Linux HCL is a another good site for information about how well certain hardware works on Linux systems.
- The Linux on Laptops site provides detailed information from users about how well different versions of Linux work on a huge number of laptops and netbooks, organized by vendor.
- In the developerWorks Linux zone, find more resources for Linux developers (including developers who are new to Linux), and scan our most popular articles and tutorials.
- See all Linux tips and Linux tutorials on developerWorks.
- Follow developerWorks on Twitter.
Get products and technologies
- Several graphical
file managers exist for Linux and UNIX environments. Examples mentioned in
this article are:
- Gigolo. This graphical application simplifies managing and browsing local and remote file systems and was originally developed for the Xfce desktop environment. Based on the GIMP Toolkit (GTK), Gigolo can be used on all Linux distributions that use the GNOME desktop or have otherwise installed GTK.
- Nautilus. This is the default graphical file manager on computer systems that use the GNOME desktop.
- Dolphin. This is the default graphical file manager on Linux systems that use the KDE desktop.
- Konqueror. This is an extremely powerful graphical file manager for Linux systems that use the KDE desktop. Konqueror was the default KDE file manager for many years and supports many capabilities that are not provided in other file managers for the KDE desktop.
- Thunar. This graphical file manager for Linux systems was originally developed for the Xfce desktop environment.
unix2dosare applications that convert text files between the formats used on Linux and UNIX, DOS, and Macintosh systems.
- Emacs is the one true text editor for modern computer systems.
- Ndisgtk is a
graphical application for interacting with the command-line
implementations that enable users to mount Windows shares without
requiring root privileges are the
smbnetfsprojects. Both of these require the
libsmbclientlibrary, which is included in the
samba-clientpackage. Neither of these have been updated for a while, which either indicates that they "just work" or that they are no longer actively used.
- See the NDISwrapper
Project page on SourceForge to get the latest version of
NDISwrapperor detailed information about using the
- See the Mono Project site for information about using Mono to run Microsoft .NET code on a Linux system.
- The Wine Project offers software that lets you run Windows software on your Linux computer. To see whether the software you're interested will run under Wine, check out the Wine AppDB.
- See CodeWeavers for a commercially supported version of Wine. See their What Runs? page for information about Windows software that is known to work with CrossOver.
- Consider running Windows in a virtual machine using VirtualBox.
- Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.
Dig deeper into Linux on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.