Is storing my password this way safe?
echo 'Write sudo password (will not be displayed) and hit enter'
read -s password
I need it to make commands like this:
echo $password | sudo -S apt-get install -y foo bar
In Linux, the sudo command allows us to execute a command or script as the superuser. However, by default, the sudo command works in an interactive mode.
If your timestamp_timeout is zero, sudo always prompts for a password. This feature can be enabled only by the superuser, however. Ordinary users can achieve the same behavior with sudo -k, which forces sudo to prompt for a password on your next sudo command.
No because you can see it via /proc/$PID/cmdline
.
I suggest not to try to reinvent security tools. The sudo
program can cache your password.
A better approach would be to edit your sudoers file and add your program that don't require password...
Do a sudo visudo
and add following to enable your admin group to run apt-get w/o password:
%admin ALL = NOPASSWD: /usr/bin/apt-get
See sudoers man page for more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With