I've been using Linux on and off (almost exclusively off) for over a year. From everything I've read, including this, you can only get temporarily elevated privileges if your account is an "sudoer". But you enter the password for the account from which you are using sudo. There is no extra knowledge that you have to provide in order to get access to the elevated privilege.
I can see how this prevents users who already have access to elevated privileges from making serious mistakes, since they spend most of the time in a mode without elevated privileges. But it doesn't really serve the same purpose as (say) in Windows, where you can initiate elevated operations from an unelevated account, as long as you provide the login information of an elevated account. I like the greater barrier that this offers to the execution of privileged operations compared to making an account into an sudoer account.
While posting to ask if there a simple way to accomplish this in Ubuntu, I was provided hints that led me to a possible solution: Adding Defaults targetpw
to /etc/sudoers
using sudo visudo
[1]. I don't want to blithely do this without confirming that it accomplishes the above without compromising security in some unanticipated way. Can those experienced with the use of /etc/sudoers
please confirm this?
Afternote
I responded to the question of whether this answers my question, and I clicked "Yes". My question became marked as a duplicate question. But the question is not duplicate, it's just that the answer applies to my question. I don't ask how to use sudo
from a standard account. I ask how to perform elevated functions, which could be using sudo
or some other means. As it turns out, one answer isn't to use sudo
from a standard account, but to transfer to a sudoer account. So the answer doesn't even address the question that I'm presumably duplicating. Another answer uses pkexec
, which also answers my question, but again, not the question that I'm presumably duplicating. Therefore, my question adds value because people will not find those two answers unless they specifically search for sudo
ing from a nonsudoer account, which those answers do not answer (and which the user might not be seeking).
Notes
su
to a sudoer account. I'm not that familiar withsu
, but it's just a matter of Googling. Thanks – user2153235 Feb 10 '23 at 04:59su sudoer-account
does exactly what I was looking for.sudo
by itself doesn't seem to because the login password is exactly the same as the password of the account from whichsudo
is being used. Did you want to post your suggestion to usesu
as the answer? It dispelled a lot of preconceptions of mine. For one thing, I thought that the sudoer list somehow played into who could usesu
(or possibly what account you cansu
to). As well, from online readings, I thought it clobbered the unelevated shell, e.g., likeexec bash
, when in fact, it acts more like a subshell. – user2153235 Feb 10 '23 at 06:15pkexec
). There is no need tosu
to another user. – muru Feb 12 '23 at 10:21pkexec --user lnxadmin whoami
, wherelnxadmin
is a sudoer account. I will modify my "Afternote" to reflect this. Thanks. – user2153235 Feb 12 '23 at 18:11