Introducing the Network Information Service for Linux

NIS is a system for sharing system information between machines. Mr. Brown tells us how to set up and use it.
Setting Up nsswitch.conf

The file used to tell your client computer which files to get from NIS and which files to get locally from the hard disk is called /etc/nsswitch.conf. This file is included with Red Hat Linux, but if you don't have a copy, you should be able to obtain a sample from a libc distribution or from the NIS-HOWTO. The file is in the same format as the one from Solaris, so if you are familiar with that one, you're a step ahead. If not, a short tutorial is useful.

The nsswitch.conf file consists of entries in the following form:


The part of the line before the colon describes the file in question, say passwd or group. The information after the colon describes how that file should be obtained. Access methods we are concerned with include nis, compat and files. The access methods are cumulative; if multiple methods are specified, they add up to create the final file. For instance, the entry

passwd: files nis
will first read the local password file, and then the NIS password file, producing a conglomeration of the two. If there are duplicate entries, the access methods coming first in the list take precedence.

Most likely, the lines all say files nisplus nis for the access methods. You don't have NIS+ running, so that method will be skipped and all will be well—you will end up with a combination of your local files and the NIS files, which is probably what you desire. However, you may want finer control over which entries users from the NIS file get added to your local file. This is where the compat access method comes in.

If you list compat as your sole access method, a special syntax in the passwd and group files is enabled. By default, the NIS version of the file isn't consulted; only the local file is used. To add entries from the NIS file, you put lines in the passwd/group file starting with a “+” character. For instance, if I wanted to add the single user steveb to my local passwd file, I would put the following line at the end of the passwd file:


The colons are place holders for fields normally included in the password file. Any information which is omitted will be filled in from the NIS file. Here, I have omitted everything but the user's name; all the other information (password, full-name field, home, shell) will be replaced automatically by NIS. Similarly, if you wanted to change steveb's shell on this computer, you might use this line as his entry:

All fields but the name and shell will be obtained via NIS. To include everyone in the password file, you would include this entry:
The lines for /etc/group are similar. If you enable the compat access method for group, you could include individual groups by including
at the end of your group file. To include only a few users (different from those listed in the NIS map) in the group, put a line such as:
where the included users are spelled out explicitly.

Using a “-” character instead of a “+” character is also possible, and does just what you would expect—it removes the specified login(s) or group(s) from the file. The one warning is that you must include “-” lines before any other line that might include the user. For instance, if jrust is included in the NIS passwd file, and you want to remove him from the local computer but give everyone else access, you would add these two lines to the end of your passwd file:


Another common situation arises where you want to exclude users from being able to login, but you want their information available in the passwd file. For this, you would add the line:

to the end of the passwd file, after previously including a few privileged users like System Administrators. Since users logging in will have no shell, they will be immediately kicked off, but all their information will be available on the computer via ypcat or the other NIS tools. One note of warning—do not put any “+” or “-” lines at the beginning of your passwd or group files or your computer will hang at boot time. This may be fixed in libc6, but with libc5 it is a problem.

The netgroup File

The netgroup file gives system administrators a powerful way for grouping users and hosts into distinctive groups which can then be referenced when setting up NIS access on the client computers. The netgroup file is maintained on the NIS master server in /etc/netgroup. It consists of the group name followed by one or more entries in the following format:


For instance, you might have a line like this:

sysadmins (,pbrown,) (,kbrown,) (,vladdy,) (,ieong,)
This would place the four users listed into the netgroup sysadmins. You can then use this special group in files such as /etc/passwd on the client using the “+/-” notation. For instance, to allow the sysadmins group access to a particular NIS client computer, but no one else, you would use an entry at the end of the passwd file like:
Note that the netgroup name is preceded by the “@” character so that NIS knows that this is a netgroup you are referring to and not a normal user name.

You can use netgroups for all sorts of creative things. Create a netgroup with dangerous users listed in it and use a “-” line in the passwd file to disallow them, but include everyone else. Create netgroups for all the “semi-private” machines you have on your network and list the valid users for those machines. Include them in your passwd file to give just those users access. The possibilities are almost endless.


White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState