can anyone give me a basic explanation on what are NSS , LDAP and PAM and what they used for and what is their relationship/differences ?
LDAP is a directory service (a type of database) along with a protocol that describes what information is stored, how to search it, etc. All kinds of things can be stored there, but in this case it'd be Unix user and group info. Very loosely, an alternative to
/etc/gshadow. Or to NIS.
NSS is glibc's name service switch. It lets you (via
/etc/nsswitch.conf) configure how various types of 'names' are resolved. Names include host names, user names, group names, and several other things. You could tell it to look up user names, group names, and passwords via LDAP instead of files.
PAM handles authentication (checking who you claim you are), authorisation (grant or deny access to a given service), session setup, etc. When you're prompted for a password, that's usually PAM's doing. By editing its config you can completely customize that (e.g., you could ask for two passwords, or none at all, or a one-time password, or...). In an LDAP setup, you'd typically configure it to check passwords via the LDAP server. It also handles password changes, which you'd configure to be done in LDAP.