Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Apparently there is a function (getpwnam) that given a username, will return the appropriate entry in /etc/passwd with the other details for that user (shell, uid, gid, etc.).

However, I have no idea how to get that function working with the shadow password file (/etc/shadow). Is this possible? If it helps, the application will be running as root.

share|improve this question
up vote 8 down vote accepted

The whole point of the shadow password file is that getpwnam doesn't return passwords from it. You need to look at man 3 shadow and getspnam in particular.

share|improve this answer

That is not possible due to 2 reasons:

  • The shadow file is one method of authentication in modern system. Some of them does not involve real password at all - what should return if user is authenticated by fingerprint? Why should it break any application?
  • Giving the hashed string for non-root application would enable off-line attacks.

It is system-specific file anyway with no so much complicated structure so if you need it you can write your own parser.

share|improve this answer

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.