LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   reverse hash for script (https://www.linuxquestions.org/questions/linux-newbie-8/reverse-hash-for-script-4175625567/)

ceantuco 03-14-2018 12:27 PM

reverse hash for script
 
Hi Guys,

I am writing a script to mount a w$ndows share so I need to provide the password for the mount command. Currently, I am providing the password in plaintext; is there a way to create a function that I could use to hash the password and use another function to unhash it so I can pass it to the mount command? The W$ndows password has not administrator rights I don't want to save the password in plaintext so curious users will not see it.

The code below is how I currently mount the w$ndows share:

Code:

mount -t  cifs //192.168.1.1/share /mnt/share -o user=linux,pass=password,cache=loose,noperm,dir_mode=0744,file_mode=0744
Please advise

dugan 03-14-2018 12:44 PM

Would the base64 command work for you?

Code:

> echo password | base64
cGFzc3dvcmQK

> echo cGFzc3dvcmQK | base64 --decode
password

> mount -t  cifs //192.168.1.1/share /mnt/share -o user=linux,pass=$(echo cGFzc3dvcmQK | base64 --decode),cache=loose,noperm,dir_mode=0744,file_mode=0744


ceantuco 03-14-2018 01:06 PM

I think base64 can work, I have never used it. I will give it a shot and let you know the outcome. Thank you!

michaelk 03-14-2018 01:15 PM

I only know of using a credentials file with the format below that contains the username and password. It is still a plain text file but can be protected with file permissions. See man mount.cifs for additional information.

Quote:

username=user
password=password
The password is being decoded in your script and anyone could run the same command in a terminal window so you are really not gaining anything.

ceantuco 03-14-2018 01:52 PM

Michael, I have used that method before and I see what you are saying; however, if I take the script and run it on a system where the text file containing the user name and password is not available, the script would fail. I would like to make the script as portable as possible. Thanks a lot!

ceantuco 03-14-2018 02:05 PM

Dugan, I followed your suggestion and it worked!
Thank you all!


All times are GMT -5. The time now is 09:23 PM.