Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Make UNIX work with Windows XP and Mac OS X

Be a good server to your client workstations

Chris Herborth (chrish@pobox.com), Freelance Writer, Freelance Developer
Photo of Chris Herborth
Chris Herborth is an award-winning Senior Technical Writer with more than 10 years of experience writing about operating systems and programming. When he's not playing with his son Alex or hanging out with his wife Lynette, Chris spends his spare time designing, writing, and researching (that is, playing) video games.

Summary:  Learn about using a UNIX® system as a primary domain controller (PDC) and file repository, including an anonymous, read-only shared area accessible by anyone with a Web browser. To be a good citizen on your local network, you need to integrate your favorite UNIX system with the networking features of client systems, generally running Windows® XP or Mac OS X. This makes it easier for the users of those workstations to take advantage of the centralized authentication and storage facilities you can provide.

Date:  18 Apr 2006
Level:  Intermediate
Also available in:   Russian

Activity:  28219 views
Comments:  

Introduction

Traditionally, UNIX® systems have been used as central servers, storing shared files and doling them out to client workstations. UNIX's powerful networking capabilities and generally rapid response to security exploits make it great for this purpose, but the plethora of tools, server applications, and client options make it a daunting task to set up and configure a system that plays nice with the sometimes random mix of client systems present on even a small Local Area Network (LAN).

The most popular desktop workstations and laptops, running Microsoft® Windows® and Apple's Mac OS X, can easily communicate with Windows servers without any additional software or configuration. Their support for Server Message Block (SMB) or Common Internet Filesystem (CIFS) networking, often referred to as Windows network, make this a natural choice. Luckily, there's a free UNIX implementation of SMB or CIFS, called Samba.

Samba implements many useful file (and print) sharing abilities, such as public shares and per-user shares, and it can even act as a Windows primary domain controller (PDC) on small networks. To provide another means of sharing public files, you'll augment this with a simple Apache Web server setup.


Before you start

If you want to follow along with this article, you'll need to pick up a few things. Everything used here is open source and freely available.

Samba is an open source implementation of the SMB or CIFS file and print sharing and network authentication, systems used by Microsoft's Windows and various other operating systems (including OS/2® and Mac OS X). This is common on Linux® systems, but less likely to be installed on other UNIX systems. If you don't have it, hit up the Samba Web site (see Resources) to get the code and install it.

Apache is the world's most popular Web server, and you've probably already got it installed and running if you're using a popular Linux distribution. If you don't have Apache up and running, head to the Apache Software Foundation Web site (see Resources), grab it, and get it going. You'll be using Apache to provide anonymous access to the public file storage areas that will be set up later.


UNIX server, desktop client

The simplest small network would be one server and one client workstation, connected through a router or switch (most home network routers have at least four ports of switch included in the device). This grows over time, usually by adding more clients and additional storage on the server. You can see this sort of network in Figure 1 below.


Figure 1. A simple, small network
a simple small network

In this setup, the server acts as a centralized location for file sharing, backups, and probably printer sharing. The clients communicate with the server and talk amongst themselves, as appropriate.

For this to all run together smoothly, you should have a single method of authenticating with the server, a way to share public file areas and private per-user file areas with the clients after they've authenticated, and maybe even an anonymous way of accessing public files for clients that haven't authenticated. This last feature is great if friends visit with their computers and want access to your network without requiring an account on the server.

The following sections illustrate one way of setting all of this up on a UNIX system using Samba and Apache.

Server authentication

To let your client workstations authenticate with the UNIX server, you're going to set up Samba as the PDC. This gives them a central location for authentication and works out-of-the-box with Windows XP Professional and Mac OS X clients. Windows XP Home doesn't support domains; if you're using XP Home on your LAN, you'll have to use a different authentication technique. See the Samba documentation (available in Resources) for more information.


Configuring Samba as a domain controller

After logging in as root, find and edit the smb.conf file (usually located in /etc/samba) using your favorite text editor. Note that you can also use sudo to edit the file as root if you'd prefer (for the rest of the article, I'm going to assume that you're logged in as root; if you're not, type sudo before any command listed here to run it as root instead of yourself).

Locate the [global] section of your smb.conf file and add the following options; if they're already present, change them to match what you see here in Listing 1.


Listing 1. Additions to Samba's [global] section

[global]
      workgroup = WORKS
      domain logons = yes
      security = user
      local master = yes
      os level = 65
      preferred master = yes
      domain master = yes
      encrypt = yes
      smb passwd file = /etc/samba/passwd
      domain logons = yes
      logon path = \\%n\profiles\%u
      logon drive = S:

This sets the domain name to WORKS (you'll probably want to change that to something else) and tells Samba to require domain logons with user-level security. That's right, user corresponds to the standard domain authentication system. It's called user because, in addition to your regular domain login name, the computers in the domain also have user accounts. The machines need to authenticate with the domain controller, before they're considered trusted systems and allowed to interact with the rest of the domain.

You also need to set up domain logons and automatic mapping of the S: drive (on Windows machines, obviously) to \\SERVERNAME\%u (replace SERVERNAME with your Samba server's name). The %u is replaced with the user's name, so it'll automatically expand to a unique share name for each user. The logon path setting is used for roaming profiles, which are used by mobile workstations (like laptops, for example).

Next you need to add a [netlogon] section for the network logon service, as seen in Listing 2.


Listing 2. The [netlogon] section

[netlogon]
      command = The domain logon service.
      path = /home/netlogon
      guest ok = yes
      public = no
      writable = no
      share modes = no

If it doesn't already exist, you'll have to create the path indicated in the [netlogon] section, and it should be empty. This share is required during authentication.

After you've made these changes, you need to add machine accounts (so the workstations are known to the domain controller, and trusted) and user accounts.


Adding machine accounts

To a domain controller, a machine is just another kind of user, and it needs to have its own account (but with a "$" at the end). You should also create a new group for the Samba users, in case you need to segregate them further. Listing 3 shows you how to do this on Fedora Core 4 Linux using the groupadd command; other UNIX systems have similar utilities or detailed instructions for adding new groups and users.


Listing 3. Adding a group and machine accounts for Samba

/usr/sbin/groupadd smbusers
for system in machine1 machine2 ; do \
    /usr/sbin/useradd -g smbusers -d /dev/null -s /dev/null $machine\$ ; \
    smbpasswd -m -a $machine ; \
done

This creates the smbusers group and then adds machine accounts for machine1 and machine2. After each user is added, its account details are added to the Samba password file.

Now you can add accounts for regular users.


A note about Windows XP machine accounts

When you first log in to the Samba server from a newly added Windows machine, you need to log in as root with the Samba server's root password. This authenticates the machine's account on the server (domain administrators adding machines to regular Windows server domains do the same thing, but with the domain Administrator account). You won't need to do this again; the user can log in to the Samba server using any valid account after the machine has been authenticated.


Adding user accounts

Adding user accounts is similar to adding the machine accounts; you need to create a user, if they don't already exist on the Samba server, and then add that user to the Samba password file using the smbpasswd command. The following code shows you how to do this on Fedora Core 4 Linux using the useradd command; other UNIX systems have similar utilities or detailed instructions for adding new users.

/usr/sbin/useradd -g smbusers username
smbpasswd -a username

This adds username to the system and to the Samba password file. You'll be prompted to set the username's password. Remember to tell them what you've set it to!


Restart Samba

Because you've changed Samba's configuration, you need to restart the two Samba daemons, smbd and nmbd, so they'll reload their configuration files. On Fedora Core 4, you'd use the following command:

/etc/rc.d/init.d/smb restart

This uses the smb init.d script (which also launches Samba when you boot) to restart the servers, as seen in Figure 2.


Figure 2. Samba restarting
Samba restarting

If your UNIX isn't Fedora Core 4, you can always use the smbcontrol command to tell the daemons to reload their configuration files:

smbcontrol nmbd reload-config
smbcontrol smbd reload-config


Shared directories

Now that you've configured Samba to work as a domain controller and told it about the machines and users on your network, you should set up some useful file shares.

At the very least, it's nice to have a personal directory on the server and a public share where authenticated users can store files for anyone to access. You'll also set up a completely open shared area where anyone can store and retrieve files.

Adding the [homes] section from Listing 4 to your smb.conf file creates the user's home directory when they log in to the Samba server. This share is invisible (not browseable) to other users, even if they've been authenticated with the server. To a client workstation, their home share is available as \\SERVER\user, where SERVER is the name of the Samba server and user is their user ID. The %S macro used as the list of valid users means the current session name, which will be the name of the currently logged in user.


Listing 4. Making users home directories available

[homes]
    comment = Home Directories
    valid users = %S
    read only = no
    browseable = no

Next up, you'll add the [public] and [shared] sections, which create the \\SERVER\public and \\SERVER\shared shared directories, respectively (where, as usual, SERVER is the name of your Samba server). These shares have nearly the same settings, but with one difference. With the [public] share, only members of the Samba users group (represented by the %G macro) are allowed to write into the share. Anyone can write into the [shared] share (see Listing 5).


Listing 5. Two public shares

[public]
    comment = Public files
    public = yes
    browseable = yes
    write list = %G
    path = /data/public

[shared]
    comment = Totally open shared area
    public = yes
    browseable = yes
    read only = no
    path = /data/shared

You should only create a completely open share like the one here if you trust the people who have access to your Samba server; open FTP servers, for example, have been compromised in the past and abused as drop boxes for pirated software.

After you've added these shares to your smb.conf configuration file, remember to either restart Samba or tell it to reload its configuration files (see the Restart Samba section).


Easier access

Now things should be working well for systems and users that want to log on to the Samba server; however, you also want to provide access through Web browsers so anyone can download files from your public shares. You'll do this by adding the shares to the Apache Web server that you have running on your Samba server.

Locate your httpd.conf file (mine is in /etc/httpd/conf) and add the code from Listing 6. These two declarations, <Alias> and <Directory>, create http://server/public/ and http://server/shared/ on the server, turn on fancy directory listings, and allow access from any Web browser.


Listing 6. Web access to the public shares

Alias /public/ "/data/public/"
<Directory "/data/public">
	Options Indexes MultiViews
	AllowOverride None
	Order allow,deny
	Allow from all
</Directory*>
Alias /shared/ "/data/shared/"
<Directory "/data/shared">
	Options Indexes MultiViews
	AllowOverride None
	Order allow,deny
	Allow from all
</Directory>

Save the file and use the apachectl command to tell Apache to reload its configuration file and activate the new URLs.

/usr/sbin/apachectl restart

In addition to having convenient Samba access to these shared directories, they're accessible to anyone with a Web browser.


Summary

By using powerful and well-supported free software, such as Samba and Apache, you can help integrate a UNIX server with Windows and Mac OS X client workstations. Samba provides authentication services by acting as a PDC. It can serve up shared directories that clients can easily mount by using standard techniques. By adding Apache to the mix, you can also easily provide unauthenticated, read-only access to public shared directories. Sharing resources is part of the point of having a LAN environment and being able to share things reduces the work associated with installing and configuring your network.


Resources

Learn

Get products and technologies

Discuss

About the author

Photo of Chris Herborth

Chris Herborth is an award-winning Senior Technical Writer with more than 10 years of experience writing about operating systems and programming. When he's not playing with his son Alex or hanging out with his wife Lynette, Chris spends his spare time designing, writing, and researching (that is, playing) video games.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX
ArticleID=108699
ArticleTitle=Make UNIX work with Windows XP and Mac OS X
publish-date=04182006
author1-email=chrish@pobox.com
author1-email-cc=