LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-07-2010, 12:17 AM   #1
digity
Member
 
Registered: Apr 2005
Posts: 105

Rep: Reputation: 15
how to pass MySQL user/pass securely in shell script?


I've written a shell script to dump a couple of MySQL databases. Currently the MySQL username and password are hard coded in the scripts as plain text. I know this is not recommended, so how do I securely pass the credentials in a script?
 
Old 01-07-2010, 12:40 AM   #2
stefansbv
LQ Newbie
 
Registered: May 2009
Distribution: Slackware
Posts: 17
Blog Entries: 1

Rep: Reputation: 9
From Advanced Bash-Scripting Guide by Mendel Cooper:

#!/bin/bash

stty -echo # Turns off screen echo.

echo -n "Enter password "
read passwd
echo
# echo "password is $passwd"
# echo

stty echo # Restores screen echo.

exit 0

# Do an 'info stty' for more on this useful-but-tricky command.
 
Old 01-07-2010, 01:10 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Just in case the user running the script is the same as the mysql user, I thought I should point out that you can just have mysql read username and password from ~/.my.cnf.

Cheers,

Evo2.
 
Old 01-07-2010, 01:50 AM   #4
digity
Member
 
Registered: Apr 2005
Posts: 105

Original Poster
Rep: Reputation: 15
@stefansbv: In your example, isn't the password still exposed in the script?
 
Old 01-07-2010, 05:33 AM   #5
vrmartin2
Member
 
Registered: Dec 2009
Location: NE Ohio
Distribution: Open SUSE
Posts: 43

Rep: Reputation: 19
Hiding the Password in Batch Mode

It's nice to hide the password during manual entry, but I too would like to know how to hide it encrypted somewhere to the script can run in batch mode. The config file is good: at least it's no longer in the script. But how can we hide it somewhere where the script can find it, decode it on the fly when it needs it, and leave it encrypted?
 
Old 01-07-2010, 05:48 AM   #6
stefansbv
LQ Newbie
 
Registered: May 2009
Distribution: Slackware
Posts: 17
Blog Entries: 1

Rep: Reputation: 9
Quote:
@stefansbv: In your example, isn't the password still exposed in the script?
What do you mean by exposed? It's not contained in the script,
but yes, you can do an echo to print it at runtime.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
How to pass arguments in a shell script? Drigo Linux - Newbie 1 11-14-2009 11:55 AM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 03:07 AM
pass php variables to shell script viveksnv Programming 1 03-04-2008 11:46 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM

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

All times are GMT -5. The time now is 03:45 AM.

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