A final way of looking at elevating our privileges is with Polkit.
Maybe it's more usable on a desktop‑based system where
we can have a GUI authenticator,
but it can still be very useful to us from the command line,
especially if we've got a failed sudo system.
On one terminal window,
we can go through and do something like pkaction. It will list all of
the defined actions that we have through PolKit.
If we go through and take a look at the default rules on the AlmaLinux system,
we'll see that members of our administrative group
are able to run all admin actions.
We're going to need to recall our current process ID
for the bash shell that we're in.
Let's remember that, and move to another terminal and have pkttyagent
‑‑process, and monitoring whatever the process ID was before.
So this is our remote authenticator.
We can return then to our original window and we can then go through, and using
pkexec, we can go through and cat out our etc/shadow file.
This is going to need elevated privileges, and it's going to ask the
authenticator to authenticate the process, so we need to return to that
second window and enter our user password.
Now it all seems rather complex.
It works better, as I say, in a desktop environment, but this can be
really useful to recover from a failed sudo entry. So let's move out to our labs to see how we can use this.