Skip to content

Instantly share code, notes, and snippets.

@CristianCantoro
Created July 19, 2024 10:18
Show Gist options
  • Save CristianCantoro/252c2485196c8216991e6ad5a52a4e6e to your computer and use it in GitHub Desktop.
Save CristianCantoro/252c2485196c8216991e6ad5a52a4e6e to your computer and use it in GitHub Desktop.
Passing the password to sudo on stdin
# 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