On 2012-09-14, houghi <hou...@houghi.org.invalid> wrote:
> When I make a bash script that needs a password, I do the following:
> #!/bin/bash
> . ~/.passwords
> echo "The password is $PASSWORD"
>
> The file ~/.passwords contains:
> PASSWORD=$SECRET
This file doesn't accomplish anything.
To use this file, the user has to store a value in the variable called
SECRET.
Whatever he stores in that varaible, he could just store it in the PASSWORD
variable in the first placed and avoid sourcing that script.
> This however leaves the .~/.password file in clear text and that is not
> a good idea, I think.
But your password file doesn't contain any secret, just the code
PASSWORD=$SECRET
You can't learn the contents of $SECRET by looking at this file.
> What would be the best way to see that this is
> not readable, while still able to use it in a standard script in the
> normal way.
You could just have these instructions:
"To use my scripts, which require a password, create a variable called PASSWORD
which contains the necessary password. For security reasons, do not store this
in a file."
For convenience, you could have some script that the users have to source in
order to set up the environment. The script will ask the user for a password,
and just keep it in a variable.
> Or am I over cautious and will it be all to no avail as people who hack
> my PC will be able to find the password anyway by running the script?
If the password is only in a volatile environment variable in your login
session, they would have to have physical access to your console, or hack a
privileged account so that they can peek into the address space of your process
to find the environment variable.
Anyway, what is this password for? Maybe that password-protected system already
has a solution for scripting. For instance if you're using the password to run
remote jobs via ssh, then you can use certificates and ssh-agent.