This is one place when windows can be much better, as users can't catch ctrl+alt+del, so you can always press that before logging in.
But I think there are some scenarios where it serves a practical security purpose as well:
- You're in an office, went away to grab a coffee and left the screen unlocked (bad!). Without sudo, a malicious person could indeed quickly install a backdoor or keylogger and take over your system.
- you're executing a third-party script on your user account. Without a password prompt, that script could trivially escalate its privileges by embedding sudo commands. With a password prompt, you'll hopefully stop and ask yourself why the script is asking for your password.
Basically, you actually cannot assuming that every running on a user account is really authorised by that user. So asking for the password is an attempt to reaffirm that it's really the user who gave that command.
> If an attacker is already in the system, it can install key logger and whatnot without the root password.
Yes, but that would require the attacker to, well, run sudo...