I am trying to change my password as a non root user :


The data is updated in /etc/shadow, but checking the permission i get:

---------- 1 root root 6076 Jan 27 17:14 /etc/shadow
cat /etc/shadow
cat: /etc/shadow: Permission denied

Clearly there were no permissions on the file for anyone, even then the passwd command succeeds, and i am indirectly updating data to a non-previliged resource (shadow file)! So can anyone explain the mechanism that how the updation takes place in background ? Explanation with reference to the system calls will be very useful.

  • Appart from @D_Bye good answer, you can use ls -l /etc/shadow before and after changing you password. You'll see that is is updated. – Archemar Jan 27 '15 at 13:10

The passwd utility is installed setuid, which means that when it runs, it runs as the user that owns the file, not as the user that called it. In this case, passwd belongs to root, so the setuid bit causes the program to run with root privileges. It is therefore able to make changes to the passwd and shadow files.

If you look at the permissions for the passwd utility, you'll see something like this:

-r-sr-xr-x  2 root  wheel   8.2K 19 Jan 17:24 /usr/bin/passwd

This is from my FreeBSD system - what you see will depend on the OS you are using. The s in the owner execute position (4th column) indicates the setuid bit.

For further reference, the syscall is setuid, and is part of the standard C library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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