Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would to like to validate a username and password correspond to a valid unix account.

The current solution I have uses expect to wait for a password prompt and then supply the password and see if the login succeeds.

Is there a kernel API or a user space function that can validate a login / password.

I guess part of my confusion is I am not sure if this is a kernel space service?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You should use pam. On debian/ubuntu you can:

apt-get install python-pam

Simple code in python pamtest.py:

See the /usr/share/doc/python-pam/examples/pamtest.py file. It's really short and does what you want.

To test it, run:

python /usr/share/doc/python-pam/examples/pamtest.py

There is also an example in C pamexample.c.

To test it:

gcc /usr/share/doc/python-pam/examples/pamexample.c -lpam -l pam_misc
./pam_misc theuser
share|improve this answer

to check if a user credentials are good you can try logging as him:

su - username

But reading about PAM may be a better route in the long term

share|improve this answer
To kick start your search, this is a page with a list of different PAM modules... kernel.org/pub/linux/libs/pam/modules.html –  Mike Keller Aug 2 '11 at 20:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.