How to just gain root permission without running anything?
When I run a command with sudo
like the following, subsequent sudo
commands will not ask for a password anymore.
sudo ls
But this still runs ls
. If I don't want to run any command at the beginning, but just stop subsequent sudo
commands from asking a password later on. Is there a way to do so?
Solution 1:
Use sudo -v
:
-v
,--validate
Update the user's cached credentials, authenticating the user if necessary.
Solution 2:
While muru's answer does exactly what you want, there's also a more general way to "do nothing," even when sudo
is not involved.
sudo true
will run the true
command, which always succeeds, and has no additional side effects, like printing to the screen, etc. There's also the false
command, which always fails. These are both useful in shell scripting.