file permission

hi frnds
can u explain
/etc/shadow file have read and write permissions for root only
but while normal user changes his passwd it also updated in that file whats the logic behind that.

If you look at the passwd command (/usr/bin/passwd on my Linux box) you will see that the permissions include a set user id (suid) bit.

-rwsr-xr-x   1 root     shadow      80268 Dec  3  2008 /usr/bin/passwd

This is indicated with an 's' instead of an 'x' in the user portion of the permissions list. The meaning of this is that when the binary is executed, its effective user id (euid) is set to the owner of the file; root in this case. Therefore, when the passwd command is executed, it is run as though root was running it and thus it is able to update the various root owned passwd and shadow files.

See:

setuid - Wikipedia, the free encyclopedia