LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2018, 12:27 PM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali, Ubuntu, OpenSuse
Posts: 655

Rep: Reputation: 42
Question 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

Last edited by ceantuco; 03-14-2018 at 12:35 PM.
 
Old 03-14-2018, 12:44 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 8,242

Rep: Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345Reputation: 3345
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

Last edited by dugan; 03-14-2018 at 12:50 PM.
 
Old 03-14-2018, 01:06 PM   #3
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali, Ubuntu, OpenSuse
Posts: 655

Original Poster
Rep: Reputation: 42
I think base64 can work, I have never used it. I will give it a shot and let you know the outcome. Thank you!
 
Old 03-14-2018, 01:15 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,233

Rep: Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217
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.

Last edited by michaelk; 03-14-2018 at 02:02 PM.
 
Old 03-14-2018, 01:52 PM   #5
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali, Ubuntu, OpenSuse
Posts: 655

Original Poster
Rep: Reputation: 42
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!
 
Old 03-14-2018, 02:05 PM   #6
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali, Ubuntu, OpenSuse
Posts: 655

Original Poster
Rep: Reputation: 42
Dugan, I followed your suggestion and it worked!
Thank you all!
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How To Manually Duplicate SHA-512 hash with a known password & hash SlowLearner Linux - Security 11 05-31-2017 06:05 AM
[SOLVED] Hash Add in a Bash Shell Script fusion1275 Linux - Newbie 3 03-24-2016 06:59 AM
LXer: Hash Tables using hash command and available implementations LXer Syndicated Linux News 0 07-16-2013 11:20 PM
Dynamically parse BibTeX and create hash of hash wakatana Programming 11 12-13-2012 04:59 PM
reverse engineer crypt(3) hash m4rtin Linux - Security 10 02-14-2010 05:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration