LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-02-2012, 09:29 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Hashing a Password using Makepasswd/MD5


I was curious to know if there was a better way of encrypting a password prior to being used in a script. In other words, I have a script that has a password inside of it and would prefer to create a hash of the password and use the hash instead of the actual password so that it if someone were to use "ps" or packet capture the transmission of the script it would be a lot harder to unscramble. Is this not a standard practice?

PHP Code:
echo "mypassword" makepasswd --clearfrom=- --crypt-md5

mypassword   
$1$Pi.JDZmY$2DWUi8J/IyAi5zDYfrmsW
So for example, I have a function in my script that uses ssh to perform a mysqldump remotely of a mysql database. So what can be added to my script that would use the hash and not use the actual password in the file?

PHP Code:
ssh_mysql_bak()
{
ssh -"PasswordAuthentication no" -"HostbasedAuthentication yes" -l username 192.168.0.1 "mysqldump --opt --all-databases -u username -pmypassword | gzip" $backup_dir/wwwsmysql$date.gz 2>> "$backup_dir/wwwmysql$date.log"

??
 
Old 04-02-2012, 09:36 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Not really, there's usually a more specific way to improve the security, using credentials files rather than directly entering details etc.

In your example, can you not run mysqldump on the client side? I can see you're gzipping the output stream but if you can allow the standard output across the network then there's no need to send the password to the remote node. You could get some improvement by running over an ssh tunnel if you did want real time network compression instead of just saving the disk space.
 
Old 04-02-2012, 12:56 PM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Many thanks

Excellent point, I was curious. In my mind I was thinking of using the hash instead of the password so if the script gets comprimised then there are looking at a hash instead of the actual password.

regards
 
Old 04-02-2012, 02:28 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well yes, but then that hash has to be understood by the target system. So basically what you'd be doing is turned an encrypted password system into an unencrypted password system, which just happens to use really weird looking passwords.
 
Old 04-02-2012, 03:39 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
A very common technique is called a "salted hash."

For example, say your password was secret. So, you generate a random number, say, 123456, and you generate an MD5 hash from the string, 123456:secret:123456, say, and you send it to the host as your authentication token: 123456:the_md5_value.

Notice how the random number (the "salt") is sent in the clear along with the MD5 string, which has been calculated from the (unknown) secret plus the (public) salt. It serves to make the process non-deterministic: you could send the string secret ten million different ways (that is to say, with a different salt-value), and the interceptor would have no way to know that the password being sent was in fact identical; nor to determine what the password is. And yet, there are no "secrets" as to the manner in which the password-string is being concealed. Eve knows exactly how Alice and Bob are masking their password, but can't wedge what it is.

Last edited by sundialsvcs; 04-02-2012 at 04:06 PM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding smb mount password in fstab? Hashing? humbletech99 Linux - Networking 6 09-13-2021 10:19 AM
Hashing multiple user:password combinations (sha) Jean-Luc Besson Linux - Software 5 12-28-2011 06:28 AM
linux password hashing indienick Programming 5 05-18-2006 02:12 PM
Command-line 'adduser': password not hashing Talesin Fedora 0 10-08-2004 08:19 PM
Linux and MD5 hashing GAVollink Programming 0 06-04-2003 01:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:18 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
Open Source Consulting | Domain Registration