Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using ldapsearch with its -y option where the password for the ldap server is read in from a file in order to ensure that the password is not left in the command history.

ldapsearch requires that the password be in a file with no newlines. The only way I am aware of for doing this is:

echo -n "myreallysecretpassword" > /path/to/password.txt

but obviously that puts the password in the command history, which is what I'm trying to avoid.

I assume there's a better way, could someone point me in the right direction?

share|improve this question
2  
If you're using bash, check your HISTCONTROL. Typically, if you prefix your command with a space, it will not be stored in your history. –  jscott May 9 '11 at 12:58
    
That's very nice @jscott, thanks. –  Eduardo Ivanec May 9 '11 at 13:00
    
Sadly our machines don't have HISTCONTROL set, and I can't really change those settings... –  Rich May 9 '11 at 13:56
add comment

2 Answers

up vote 1 down vote accepted

Create the file however you want and just printf it without newline.

cat pw.txt | awk '{printf $1 }'

or

printf `cat pw.txt`
share|improve this answer
    
That works great, but it still means that the password appears in the process list if someone manages to view it at just the right time. In the end I have combined your answer with @Eduardo's: cat password.txt | awk '{printf $1}' > new_password.txt. –  Rich May 9 '11 at 14:03
add comment

You can use read to input an intermediate variable semi-securely:

read -s tempvar # enter your password and press enter - it will not echo back
echo -n $tempvar > pw.txt
unset tempvar

Of course if you're worried mostly about the command history you can disable it in bash like this:

export HISTFILE=
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.