A
A
animunculus2020-04-14 16:41:24
linux
animunculus, 2020-04-14 16:41:24

Why can Linux users change their password with the passwd command if they don't have permission to write the /etc/shadow file?

/etc/shadow can only be modified by root, other users cannot modify or view it. But if the user changes his password on his own, the changes will still be written to the file.
How it works?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2020-04-14
@animunculus

read about special access rights SUID and SGID, which allow you to run programs on behalf of other users. Several programs have this flag, popular ones are passwd, sudo

$ ls -sl1sFa /usr/bin/sudo /usr/bin/passwd
 60 -rwsr-xr-x 1 root root  59640 Mar 22  2019 /usr/bin/passwd*
148 -rwsr-xr-x 1 root root 149080 Jan 31 17:18 /usr/bin/sudo*

the letter "s" in the first three means that there is a SUID attribute, so the program will be run as the owner of the file (root).
PS This does not work with scripts, only with binaries, since scripts implicitly call the interpreter separately.

S
Sanes, 2020-04-14
@Sanes

Because not users write to this file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question