Best way to hide password in bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Best way to hide password in bash script?
# 1  
Old 04-11-2010
Best way to hide password in bash script?

Dear folks,

The title of my thread says mostly all of what I want to do. Basically I want to auto-ssh to a remote host, and run a program on it (VLC is just an example). I wrote a script which calls xterm and then runs expect on it. The code is as follow
Code:
#!/bin/bash

export PASS="xxxxxxx"
xterm -T VLC -e "(expect -c \"
set timeout -1
spawn ssh -X user@192.168.1.2 \\\"vlc\\\"
match_max 100000
expect \\\"*?assword:*\\\"
send -- \\\"$PASS\\r\\\"
send -- \\\"\\r\\\"
interact\") &> /dev/null"

Obviously, one can use ps to reveal what is happening
Code:
$ ps -elf | grep vlc
0 S user 11371 11370  0  80   0 -  2599 select 16:14 pts/1    00:00:00 xterm -T VLC -e (expect -c "?set timeout -1?spawn ssh -X user@192.168.1.2 \"vlc\"?match_max 100000?expect \"*?assword:*\"?send -- \"xxxxxxx\r\"?send -- \"\r\"?interact") &> /dev/null
0 S user 11372 11371  0  80   0 -  1111 wait   16:14 pts/2    00:00:00 bash -c (expect -c "?set timeout -1?spawn ssh -X user@192.168.1.2 \"vlc\"?match_max 100000?expect \"*?assword:*\"?send -- \"xxxxxxx\r\"?send -- \"\r\"?interact") &> /dev/null
0 S user 11373 11372  0  80   0 -  2982 futex_ 16:14 pts/2    00:00:00 expect -c ?set timeout -1?spawn ssh -X user@192.168.1.2 "vlc"?match_max 100000?expect "*?assword:*"?send -- "xxxxxxx\r"?send -- "\r"?interact
0 S user 11375 11373  0  80   0 -  1363 select 16:14 pts/3    00:00:00 ssh -X user@192.168.1.2 vlc
0 S user 11398 11381  0  80   0 -   834 pipe_w 16:14 pts/4    00:00:00 grep vlc

and then one can easily see the password I put in the code.

The primary reason for the code is to create a ready-to-run program for non-tech people (who have no idea about unix, about ssh, and who are not given ssh account as well), and of course I do not want them to know my password. Of course, they might be so novice that they might not know that ps command, but I just want to have some security for myself.

Any idea or advice will be greatly appreciated,

PS: the host is linux (red hat), and clients are Mac OS X (so expect and ssh can be used)

D.

Last edited by dukevn; 04-11-2010 at 05:32 PM.. Reason: Added PS
# 2  
Old 04-11-2010
# 3  
Old 04-11-2010
Quote:
Originally Posted by danmero
Thanks danmero for your suggestion. I want to avoid this as well, because I want to create a ready-to-run program, no need to type anything else (pass phrase for example).

D.
# 4  
Old 04-11-2010
Whenever I post a script on my blog and include my email address, I obfuscate it with the tr command to thwart spambots. It could be used here too. If the pass was LinuxRules you could use
Code:
pass=$(echo "LinZxRZles | tr "Z" "u")'

You could also use parameter expansion to pick out the password from a longer random-looking string. None of this provides security, just a little confusion for curious novices.
# 5  
Old 04-11-2010
# 6  
Old 04-11-2010
Quote:
Originally Posted by dukevn
(...) no need to type anything else (pass phrase for example).
You can create a key pair whithout passphrase. You'll only need to give the password once for the key transfer.
# 7  
Old 04-11-2010
Quote:
Originally Posted by fubaya
Whenever I post a script on my blog and include my email address, I obfuscate it with the tr command to thwart spambots. It could be used here too. If the pass was LinuxRules you could use
Code:
pass=$(echo "LinZxRZles | tr "Z" "u")'

You could also use parameter expansion to pick out the password from a longer random-looking string. None of this provides security, just a little confusion for curious novices.
Your tr'ing way is interesting fubaya. Honestly I have not heard of tr before. Anyway, that is just to protect the bash script itself, not the information produced by ps. The second way (which I thought of as well, by creating a complicated script to select the password that I want) does not help in case of ps either.

D.

---------- Post updated at 08:15 PM ---------- Previous update was at 08:12 PM ----------

shc is great, I just tried it and it works great for its purposes. Thanks for this information danmero, although again, it helps protecting the bash script, but the password still shows up when ps'ing.

D.

---------- Post updated at 08:23 PM ---------- Previous update was at 08:15 PM ----------

Quote:
Originally Posted by frans
You can create a key pair whithout passphrase. You'll only need to give the password once for the key transfer.
I am not sure if I miss something, but I am also using ssh without password in another box. Some points should be pointed out:

* This method needs some setups on clients (creat and copy ssh key etc...)
* This method needs passphrase each time a new shell is created on host (or first time user logs in), which is my case. Our remote host is a cluster, and each time I log on, a new shell is created.

The first point alone needs a lot of works, which is opposed to what I want to do: my program should be ready to run in any new client in the network without any complicated setup.

Thanks,

D.

---------- Post updated at 08:41 PM ---------- Previous update was at 08:23 PM ----------

I think of some solutions:

* fool ps so that the processes showed by ps'ing (xterm, bash... ) are something else (fake name) or without parameters (such as xterm, or expect or bash only)

* temporary disable ps (by chmod 500 `which ps` for example, which needs root privilege) or temporary link ps to a modified ps which does not show the processes I want to hide)

* encrypted password so that ps shows only weird characters on password fields (not sure if this is doable)

Google gave me some *change name or title of processes*, but it seems to me that those work only for the script, not the processes called by the script (like ssh, expect etc...)

Any other ideas?

Thanks,

D.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to hide password in shell script?

I am writing a shell script for sql loader (just copy part of the code) : For security reason, I have to put the below loginName and password into another separate file instead of in the same file of this script. Anyone can give me a hand. Thanks. Shell Script :... (12 Replies)
Discussion started by: Jaewong
12 Replies

2. Shell Programming and Scripting

Hide password from processes in Linux

i have a shell script which calls a java program with username and password arguments. #!/bin/ksh #set some classpaths here #finally run the command java com.test -u $U -p $P Now when i run it, the password shows up in the list of processes. I am not the admin on the server so cant... (3 Replies)
Discussion started by: ariesb2b
3 Replies

3. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

4. Shell Programming and Scripting

Expect Script - Hide password from process table

i have an expect script that runs like this: /usr/bin/expect -f /home/skysmart/commandstoexecute.sh host2.net b$4aff Skysmart when i run this command, and i do a ps -ef and egrep for expect, i see the exact line in the process table and it shows my password for the world to see. how can i... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

How to hide/encrypt password in script?

Hi I have following problem Im writing a script (in bash ) , where need to be written login & passwd for databas client . Its need to in following form login passwd@dbhostname . The problem is so anybody can read it so the passwd & login are visible and thats not very safety . Can... (8 Replies)
Discussion started by: kvok
8 Replies

6. UNIX for Dummies Questions & Answers

How can i hide username/password

hi all, i run sqlplus command on unix(HP-UX) like "sqlplus username/password@serverA @deneme.sql" but when someone run "ps -ef | grep sqlplus", it can see my username and password :( How can i hide username and password. thanx. (1 Reply)
Discussion started by: temhem
1 Replies

7. Shell Programming and Scripting

How Do I Hide the Password in a Script

Hi, I am writing a UNIX .ksh script and need to send the login password of the login id that is executing the script to a command that I am executing in the script. I don't want that password to be seen by anyone except whoever is executing the script. Does anyone know how I can accomplish... (6 Replies)
Discussion started by: samd
6 Replies

8. Shell Programming and Scripting

Want to hide password

All, In my script I am calling another script.. in that script I need to enter a password. Problem is that everyone is able to see the password when I enter that. Is there any way that when i enter that password it should not display or may look like *******. Or if there any other way that I... (1 Reply)
Discussion started by: arpitk
1 Replies

9. Shell Programming and Scripting

How to hide password on Linux?

Hi falks, I have the following ksh code: echo "Enter VS Admin password:" oldstty=`stty -g` stty -echo intr '$-' read password stty $oldstty echo This code ask from a user to enter his password. The OS suppose to hide the entering of the... (2 Replies)
Discussion started by: nir_s
2 Replies

10. Programming

hide password typing

I am doing a project in C program which requires to type in password in Unix terminal. Does anybody know how to shade or not output any words typed by user in the terminal? I use the function scan() to read typing from user. Thanks in advance. (2 Replies)
Discussion started by: ivancheung
2 Replies
Login or Register to Ask a Question