Created
July 19, 2024 10:18
-
-
Save CristianCantoro/252c2485196c8216991e6ad5a52a4e6e to your computer and use it in GitHub Desktop.
Passing the password to sudo on stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if you prepend spaces your password is not saved in ~/.bash_history | |
# (assuming you have the default configuration) | |
# Options: | |
# * `--stdin/-S` read the password from stdin | |
# * `-v` is used to refresh the credentials cache without issuing a command | |
# * `-p ''` mutes the prompt | |
# using echo | |
sudo -p '' --stdin -v < <(echo '<password>') | |
# using printf | |
printf '<password>\n' | sudo --stdin -p '' -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment