Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted

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

apt-get install python-pam

Simple code in python

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

To test it, run:

python /usr/share/doc/python-pam/examples/

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... – 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.