Bash scripting mask password from ps


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash scripting mask password from ps
# 1  
Old 09-20-2018
Bash scripting mask password from ps

Hi All,


I have a script, which prompts me for my password input, then it passes that password onto an argument for another script which is then passed onto an expect script which automates my logins to a bunch of servers to execute my commands.

example.

script A - request for password, pass password variable to expect script command
expect command - ./expect $password ssh@server “command”
expect script - obtain password from $argv 0 and execute.


I've seen a few posts about this request and can't find anything that works. Is anyone able to guide me in the right direction? I have tried using file descriptor and no luck.

Also, no ssh keys is not an option and hard coding passwords in files.

Thanks

Last edited by aixkidbee; 09-20-2018 at 12:15 PM..
# 2  
Old 09-20-2018
You can pass information in environment.
Example
Code:
PW=this_is_secret ./script ...

And modify your ./script to use $PW
# 3  
Old 09-20-2018
Quote:
Originally Posted by MadeInGermany
You can pass information in environment.
Example
Code:
PW=this_is_secret ./script ...

And modify your ./script to use $PW

That is not going to work. As I said I don't want the password viewed which that will most definitely be visible to ps listing. Smilie

Last edited by MadeInGermany; 09-20-2018 at 01:18 PM.. Reason: I pressed the wrong button - nothing modified I hope
# 4  
Old 09-20-2018
I don't think ps would see anything more than the variable name, but I could be wrong. Its hard to tell without seeing the whole code.

I don't know how much more coding you wish to do with the script, but one option might be to use gpg to encrypt a file with the password or passwords in it. Then you could just use the password to decrypt the file in the script and pass the real password or passwords to a variable in that script when decrypted.

Ansible may be a good tool for that as well. Again, hard to say without looking at the code.
# 5  
Old 09-20-2018
The prefixed PW= is a temporary environment assignment in the invoking shell, and not part of the command arguments.
Comparable to
Code:
export PW=top_secret; ./script ... ; unexport PW

Access via ps ewww or pargs -e or /proc/pid/environ is denied for other (non-root-)users.
# 6  
Old 09-20-2018
Quote:
Originally Posted by MadeInGermany
The prefixed PW= is a temporary environment assignment in the invoking shell, and not part of the command arguments.
Comparable to
Code:
export PW=top_secret; ./script ... ; unexport PW

Access via ps ewww or pargs -e or /proc/pid/environ is denied for other (non-root-)users.
Exporting a env variable e.g export PW=hi
./script PW ssh user@server "date"

This will not work. It will NOT pass the password argument PW variable to ps output, but the actual password itself.

Here is what I captured as another user other than my own.
xxxxx 15728704 14745672 0 00:32:28 pts/2 0:00 ./script hi ssh -o StrictHostKeyChecking=no user@server date

Clearly showing the password.
# 7  
Old 09-21-2018
In post#2 I said
Code:
 modify your ./script to use $PW

It must use $PW instead of $1
Then you can pass "dummy" to $1, or you rewrite the script further to not need a "dummy" argument.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

What is mask and effective right mask in setfacl?

Hi Guys, can someone explain what is mask and effective right mask in setfacl and getfacl command with example, unable to get it. (3 Replies)
Discussion started by: Jcpratap
3 Replies

3. Red Hat

Samba create mask and dir mask on RHEL 4.8

Hi Experts, I'm using samba -3.6.1 on Red Hat Enterprise Linux ES release 4 (Nahant Update 8) ,all seems ok. The issue im facing is as follows. When ever a user creates a file via windows explorer the permissions assgined to the file are as follows -rw-rwxr--+ 1 tom group2 0 Mar 9... (1 Reply)
Discussion started by: maverick_here
1 Replies

4. Shell Programming and Scripting

Scripting password prompt for restarting Jboss application

Hi When I do on console a stop, the script prompts for password > stop_idm_suite.sh Suite system password:Here experct of the shell script stop_idm_suite.sh DoIt() { # prompt System password echo "" ${BMC_JAVA_HOME}/java -Didm.suite.home=${BMC_IDM_SUITE_HOME} -classpath... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

5. UNIX for Dummies Questions & Answers

how to mask the password ?

Hi All, i am executing peoplesoft sqr command from unix prompt which has the unix id/password as parameter along with other parameters. i want to show whole command in log file but want to mask the id/password field. this command i am executing in shell script. Please suggest.. >sqr sqrname... (2 Replies)
Discussion started by: avi.coep
2 Replies

6. Shell Programming and Scripting

Scripting help/advise on hiding/masking username/password

Hi, I currently have a UNIX script with a function that uses a username and password to connect to the database, retrieve some information and then exit. At the moment, am getting the username and password from a hidden plain text file and permission set to -r--------, i.e. read only to who... (1 Reply)
Discussion started by: newbie_01
1 Replies

7. Shell Programming and Scripting

Scripting password changes.

Hello, I am looking for a way to login to multiple machines and do things such as create users, reset root passwords etc non interactively. The problem with the passwords is that all machines use ssh, dont allow root login, require to login as a normal user, su to root then change the root... (1 Reply)
Discussion started by: Actuator
1 Replies

8. Shell Programming and Scripting

scp scripting without asking password

I like to copy a file from one server server1 from path path1 to another server server2 to path path2. User logging in both the servers are same say user1 I tried to use ssh to generate public/private key pairs and then copy without prompting for password. These are the steps i followed ... (5 Replies)
Discussion started by: jwala
5 Replies

9. Shell Programming and Scripting

scripting password prompts

Hi there Probably a really simple question but I am writing an install script and at certain stages of the install (ie creating a table in mysql) the system prompts for you to enter a password, I was wondering, how do I script this input so that the install doesnt keep stopping for manual... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

10. Programming

password mask in C

Hi, Could any one help me to write a C program for password mask with ******. I mean whatever word i will type that will show on the screen as ***** and should store the correct value in a variable. Thanks in advance Krishna (5 Replies)
Discussion started by: krishna
5 Replies
Login or Register to Ask a Question