I've been noticed that normal users can change their own passwords without sudo. But as far as i know, to change password has to write the /etc/shadow file which is accessible only by root.
How does that happen??
The easiest way to do that is to log in as a root or sudo user, as you can use the passwd [username] command to change the user password easily. Remember that non-root sudo users will have to use the sudo passwd command instead. Plus, they will have to enter their passwords to proceed with the command.
How a non-root user can change his own password when he does not have write permission to the /etc/shadow? The effect is that a passwd process adopts the identity of the owner, in this case root. This is how it can modify the shadow file.
sudo instead of su - . sudo ("super user do") is a command that lets you run other commands as root temporarily. This is the best way for most users to run root commands, as the root environment is not maintained, and the user doesn't need to know the root password.
Enter the following: mount -o remount rw /sysroot and then hit ENTER. Now type chroot /sysroot and hit enter. This will change you into the sysroot (/) directory, and make that your path for executing commands. Now you can simply change the password for root using the passwd command.
The passwd
program in installed setuid root:
$ ls -l `which passwd`
-rwsr-xr-x 1 root root 41284 Sep 12 2012 /usr/bin/passwd
Note the s
in the fourth position. This is a flag that can be set in the file permissions that tells Linux to assume the privileges of the user that owns the executable when it is run - in this case, root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With