Wednesday, July 6, 2011

NIS on Solaris 10

Setting up a simple NIS evironment in Solaris 10

1 Introduction

1.1 Purpose
This document describes how to setup a Network Information System (aka NIS) enviroment with one master server and one client.

1.2 Preparation
TCP/IP should be running on all systems that should be part of the NIS environment. All clients should be mentioned in the /etc/hosts file of nfs server server_nis.
I am using NFS and Automount in this document.


2 List all NIS services


# svcs "*nis*"
STATE STIME FMRI
disabled 13:09:23 svc:/network/rpc/nisplus:default
disabled 13:09:39 svc:/network/nis/update:default
disabled 13:09:39 svc:/network/nis/server:default
disabled 13:09:39 svc:/network/nis/xfr:default
disabled 13:09:40 svc:/network/nis/passwd:default
disabled 13:09:43 svc:/network/nis/client:default


3 Setting up NFS server server_nis


A NIS server does not need a NFS server to operate correctly. But NIS is mostly used to accomodate roaming user in a Unix environment. In this environment NIS is used to make the user databases available on the network. NFS is the used to make the home directories available.

3.1 Setting up NFS

# vi /etc/dfs/dfstab
+-------------------
| share -F nfs /export/home

# svcadm enable nfs/server

# shareall

3.2 Configure automount

# vi /etc/auto_home
+------------------
| * server_nis:/export/home/&


4 Create an extra user


# useradd -d /export/home/user1 -m -s /usr/bin/bash user1
# usermod -d /home/user1 user1

5 Setting up NIS server server_nis

5.1 Create the files needed with NIS

# cp /etc/nsswitch.nis /etc/nsswitch.conf

# domainname nis.world
# domainname > /etc/defaultdomain

# cd /etc
# touch ethers bootparams locale timezone netgroup netmasks

5.2 Make server_nis a Master server

# ypinit -m
-- Output skipped --
next host to add: server_nis
next host to add:
The current list of yp servers looks like this:

server_nis

Is this correct? [y/n: y] y

-- Output skipped --

Do you want this procedure to quit on non-fatal errors? [y/n: n] n

5.3 Check the NIS daemons status
# svcs nis/server

5.4 Create the NIS maps
# cd /var/yp
# /usr/ccs/bin/make

5.5 Test the master NIS server server_nis
# ypwhich
# ypwhich -m
# ypcat hosts
# ypmatch server_nis hosts
# ypmatch user1 passwd

6 Configure NIS client client_nis

6.1 Configure automount
# vi /etc/auto_home
+------------------
| * server_nis:/export/home/&

6.2 Create the files needed with NIS
# cp /etc/nsswitch.nis /etc/nsswitch.conf

# domainname nis.world

# domainname > /etc/defaultdomain

6.3 Make client_nis a NIS client

# ypinit -c
-- Output skipped --
next host to add: server_nis
next host to add:

6.4 Start the NIS daemons
# svcadm enable nis/client

6.5 Reboot the system
# init 6

6.6 Testing the NIS client (client_nis)
# ypwhich
# ypwhich -m
# ypcat hosts
# ypmatch user1 passwd


7 Adding an extra user to NIS


7.1 Adding the user on the master server (server_nis)
# useradd -d /export/home/user2 -m -s /usr/bin/bash user2
# usermod -d /home/user2 user2

# passwd user2

7.2 Updating the NIS maps on the master server (server_nis)
# cd /var/yp
# /usr/ccs/bin/make

7.3 Using new user to log in
Go to NIS client client_nis and try to log in as user2.

8 Set up NIS slave server slave_nis


8.1 Create the files needed with NIS
# cp /etc/nsswitch.nis /etc/nsswitch.conf

# domainname nis.world
# domainname > /etc/defaultdomain


8.2 Make iene a NIS client
# ypinit -c

-- Output skipped --
next host to add: server_nis
next host to add: slave_nis
next host to add:
* Make sure that the ypserv process is running on the NIS master server *
# svcadm enable nis/client

8.3 Make slave_nis a slave server
# ypinit -s server_nis
-- Output skipped --
Do you want this procedure to quit on non-fatal errors? [y/n: n] n
# svcadm disable nis/client
# svcadm enable nis/server

9 Securing NIS

9.1 /etc/securenets
In the default installation of NIS, any host that can reach the NIS master server or Slave server can connect as a client and look at the contents of the NIS map files. To overcome this problem you can use the /etc/securenets file.

9.1.1 Create securenets
# vi /etc/securenets
o-------------------
| # Grant access to a specific host
| hosts 172.16.60.x
|
| # Grant access to all hosts on a subnet
| 255.255.255.0 172.16.60.0

9.2 passwd.adjunct
Another problem with the default setup of NIS is that all users can retrieve the compiled password of any user account in the NIS passwd map. This is because NIS joins the /etc/passwd and /etc/shadow file into one passwd map.
User can read the passwd map by running the ypcat passwd command.
$ ypcat passwd | grep abhi
abhi:QWasxs.poskw4:1000:1:MeMyselfI:/home/abhi:/bin/bash
The passwd.adjunct file can be used to remove the encrypted password from the ypcat command output.

9.3 Creating passwd.adjunct
# mkdir /var/yp/security

# chown root security
# chmod 700 security
# nawk -F\: '{printf("%s:%s:::::\n",$1,$2)}'
/etc/passwd > /etc/security/passwd.adjunct

9.3.1 Fixing the passwd file
# cp /etc/passwd /etc/passwd.original
# nawk -F\:
'{printf("%s:##%s:%s:%s:%s:%s:%s\n",$1,$1,$3,$4,$5,$6,$7)}'
/etc/passwd > /etc/passwd.new

# cat /etc/passwd.new
Check if the passwd.new file is correct.
# cp -i /etc/passwd.new /etc/passwd cp: overwrite /etc/passwd (yes/no)? yes

9.3.2 Generate new map files
# cd /var/yp
# /usr/ccs/bin/make

9.3.3 Test Configuration

# ypmatch abhi passwd
abhi:##abhi:1000:1:MeMyselfI:/home/abhi:/bin/bash

LDAP Server on Solaris x86 Platform

1 Create Domain

1.1 Set default domain

Assume that you are working on the following host: abhi with ip address 172.16.60.33

root@abhi # domainname testing.ldap
root@abhi# domainname > /etc/defaultdomain

1.2 Add host

Add the string abhi.testing.ldap to your hosts file.

root@abhi# vi /etc/inet/hosts
+--------------------------
| 172.16.60.33 abhi abhi.testing.ldap loghost

2 Install the LDAP server

The LDAP Server is installed with the following packages: IPLTdsu (IPLTnls, IPLTnspr (IPLTnss, IPLTjss), IPLTpldap).

Make sure that these packages are installed on your machine.

Insert the Solaris 10 DVD into the drive.

root@abhi# cd /cdrom/cdrom0/Solaris_10/Product

root@abhi# pkgadd -d . IPLTnspr
root@abhi# pkgadd -d . IPLTnss
root@abhi# pkgadd -d . IPLTjss
root@abhi# pkgadd -d . IPLTnls
root@abhi# pkgadd -d . IPLTpldap
root@abhi# pkgadd -d . IPLTdsu
root@abhi# pkgadd -d . IPLTdsr

root@abhi# cd /
root@abhi# eject cdrom

3 Create basic LDAP Server setup

root@abhi# directoryserver setup
Would you like to continue with configuration? [Yes]:
Press enter
Select the component you want to configure [1]:
press enter
Choose a configuration type [2]:
press enter
Specify the components you wish to configure [All]:
press enter
Specify the components you wish to configure [1, 2]:
press enter
Specify the components you wish to configure [1, 2]:
press enter
Computer name [abhi.testing.ldap]:
press enter
System User [nobody]:
press enter
System Group [nobody]:
press enter
Do you want to register this software with an existing iplanet
configuration directory server? [No]:
press enter
Do you want to use another directory to store your data? [No]:
press enter
Directory server network port [389]:
press enter
Directory server identifier [abhi]:
press enter
iPlanet configuration directory server administrator ID [admin]:
press enter
Password:
abhi123
Password (again):
abhi123
Suffix [dc=testing, dc=ldap]:
press enter
Directory Manager DN [cn=Directory Manager]:
press enter
Password:
abhi1234
Password (again):
abhi1234

Administration Domain [testing.ldap]:
press enter
Administration port [24459]:
5100
Run Administration Server as [root]:
press enter
Press return to continue...
root@abhi#


4 Prepare the Directory Server


root@abhi# cd /usr/lib/ldap
root@abhi# ./idsconfig
Do you wish to continue with server setup (y/n/h)? [n] y

Enter the iPlanet Directory Server's (iDS) hostname setup:
abhi
Enter the port number for iDS (h=help): [389]
press enter
Enter the directory manager DN: [cn=Directory Manager]
press enter
Enter passwd for cn=Directory Manager :
abhi1234
Enter the domainname to be served (h=help): [testing.ldap]
press enter

Enter LDAP Base DN (h=help): [dc=testing,dc=ldap]
press enter
Enter the profile name (h=help): [default]
press enter
Default server list (h=help): [172.16.60.33]
press enter
Preferred server list (h=help):
press enter

Choose desired search scope (one, sub, h-help): [one]
press enter
Choose Credential level [h=help]: [1]
2
Choose Authentication Method (h=help): [1]
2
Do you want to add another Authentication Method?
n
Do you want the clients to follow referrals (y/n/h)? [n]
press enter

Do you want to modify the server timelimit value (y/n/h)? [n]
press enter
Do you want to modify the server sizelimit value (y/n/h)? [n]
press enter
Do you want to store passwords in "crypt" format (y/n/h)? [n] y
Do you want to setup a Service Authentication Methods (y/n/h)? [n]
press enter

Client search time limit in seconds (h=help): [30]
press enter
Profile Time To Live in seconds (h=help): [43200]
press enter
Bind time limit in seconds (h=help): [10]
press enter
Do you wish to setup Service Search Descriptors (y/n/h)? [n]
press enter
Enter config value to change (1-19 0=commit changes) [0]
press enter

Enter DN for proxy agent: [cn=proxyagent,ou=profile,
dc=testing,dc=ldap]
press enter
Enter passwd for proxyagent:
proxy
Re-enter passwd:
proxy
WARNING: About to start committing change. (y=continue, n=EXIT)
y

root@abhi#

5 Configure first LDAP client


5.1 Create client system description (ldif file)
On the LDAP server.
root@abhi# vi /tmp/host1.ldif
dn: cn=host1,ou=hosts,dc=testing,dc=ldap
changetype: add
cn: host1
iphostnumber: 172.16.60.34
objectclass: top
objectclass: device
objectclass: ipHost

5.2 Load ldif file in LDAP server
ldis stands for LDAP data interchange format.
On the LDAP server.
root@abhi# ldapmodify -c \
> -D "cn=directory manager" \
> -w abhi1234 \
> -f /tmp/host1.ldif

5.3 Set default domain on client
On the LDAP client.
client # domainname testing.ldap
client # domainname > /etc/defaultdomain

5.4 Add server to hosts file
Add the string abhi.testing.ldap to your hosts file.
On the LDAP client.
client # vi /etc/inet/hosts
+--------------------------
| 172.16.60.33 abhi abhi.testing.ldap loghost

5.5 Configure first client as a LDAP Client

client # ldapclient \
> -v init \
> -a proxypassword=proxy \
> -a proxydn=cn=proxyagent,ou=profile,dc=testing,dc=ldap \
> -a domainname=testing.ldap \
> 172.16.60.33

6 Populate LDAP databases

Edit /etc/hosts on the client so that it only contains the hosts you want to store in LDAP.
client # vi /etc/hosts
client # ldapaddent \
> -D "cn=directory manager" \
> -w abhi1234 \
> -a simple \
> -f /etc/hosts hosts

6.1 Check hosts database
client # ldaplist hosts

6.2 Populate passwd database
client # ldapaddent \
> -D "cn=directory manager" \
> -w abhi1234 \
> -a simple \
> -f /etc/passwd \
> passwd

client # ldapaddent \
> -D "cn=directory manager" \
> -w abhi1234 \
> -a simple \
> -f /etc/shadow \
> shadow


7 Listing content of LDAP server


client # ldaplist
client # ldaplist passwd
client # ldaplist hosts


8 Configure all other clients


All other clients can be configured through:


8.1 Set default domain


client # domainname testing.ldap

client # domainname > /etc/defaultdomain

8.2 Add LDAP client to hosts file
client # vi /etc/inet/hosts
+--------------------------
| 172.16.60.x clientname clientname.testing.ldap loghost

8.3 Configure as LDAP Client
clientname # ldapclient \
> -v init \
> -a proxypassword=proxy \
> -a proxydn=cn=proxyagent,ou=profile,dc=testing,dc=ldap \
> -a domainname=testing.ldap \
> 172.16.60.33