ages04
ages04

Reputation: 6387

Python Unix authentication

I need to do a simple authentication of username's which are on the host and NIS. I am writing this code in Python.
I tried using PAM to do authentication. For this I downloaded a Python module called Python Pam.

The code I use :

import pam   
pam.authenticate('root',<password>,<service>)

where <service> is a config file I created in /etc/pam.d/
the file contains the following code

#%PAM-1.0
auth     requisite      pam_unix.so

This code works on certain hosts giving the correct answer, but not on others
Even if I replaced <service> with login or sshd as in

pam.authenticate('root',<password>,'sshd')

It still returns False for a correct password on certain hosts.

So does anybody know why this does not work. I don't need to use pam or any module. Is there any command in unix that I can invoke from Python which would just authenticate a username? and preferably work across all unix based systems including Linux, Solaris, HP-UX, AIX.
Thanks

Upvotes: 2

Views: 3011

Answers (2)

zakhur
zakhur

Reputation: 11

The answer to that lies in the third parameter in the /etc/pam.d/ file you created.

Try this command on the machines where it does not work. Yes, you must be root or sudoer root.

# ldconfig -v |grep pam_unix.so

Most likely a symlink does not lead to the real pam shared library from pam_unix.so. Add it or change the config file parameter to something that ld can use to find the link.

Upvotes: 1

Lennart Regebro
Lennart Regebro

Reputation: 172349

Both

 pam.authenticate('myusername', 'mypassword', 'sshd')

and

 pam.authenticate('myusername', 'mypassword')

Login works fine on my machine. The documentation for the pam module is pretty much non-existent, so if you configured your service correctly or not is hard for me to say.

Upvotes: 1

Related Questions