We want that some users should be able to do e.g. sudo
and become root,
Well, that's the problem sudo is designed to solve, so that's easy.
but with the restriction that the user can't change root password.
You can, as SHW pointed out in a comment, configure sudo to only allow certain actions to be taken as root by certain users. That is, you can allow user1 to do sudo services apache2 restart
, allow user2 to do sudo reboot
but nothing else, while allowing the hired-as-system-administrator user3
to do sudo -i
.
However, a user that has been granted the ability to sudo -i
or sudo
into a shell (sudo bash
, for example) can do anything. That is because by the time sudo launches the shell, sudo itself is out of the picture. It provides the security context of a different user (most often root), but has no say in what the executed application does. If that application in turn launches passwd root
there is nothing sudo can do about it. Note that this can be done through other applications, too; many more advanced editors provide facilities to execute a command through the shell, which will be executed with the effective uid of that editor process (that is, root).
That is, a guarantee that we still can login to that server and become root no matter of what the other users will do.
Sorry; that can't be done. A quick "sudo rm /etc/passwd" or "sudo chmod -x /bin/bash" (or whatever shell root uses) and you are pretty much hosed anyway. "Pretty much hosed" meaning "you'll need to restore from backup and hope they didn't do anything worse than a slip of fingers".
By giving unfettered root access on a system to a user, you trust that user (including any software they might choose to execute, even something as mundane as ls) to not have malicious intent, and to not mess up by accident. That's the nature of root access.
If you can't trust them with that level of access, you'll need either a very tightened down sudo configuration, or to simply not grant the user in question root access at all.
sudo
to grant permission for specific root-privileged application only. In that way, user will not be allowed to change the root password – SHW 17 hours agosudo
can handle different level of authorization with groups and single user with thevisudo
commands, it's not easy, but it does work – Kiwy 17 hours agosudo
for these users. If you don't trust them, don't give themsudo
access in the first place. Also note that ideally, root should not have a password at all, but you should use other means of authenticating. (Which the user will still be able to "hack", even if you would protext/etc/passwd
) – Anony-Mousse 14 hours agosudo
andsetuid
can solve most problems. – bdowning 9 hours ago