0

Is one of the following considered more standard than the others when storing credentials?

export DB_USER='aodhfoi2'

export DB_USER = aodhfoi2

export DB_USER="aodhfoi2"

Or, something else? Basically I'm looking to standardize various credentials and I haven't found a consistent example in what I've seen in various places on Google so was wondering if someone could recommend the best way to go about this.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    What you are actually comparing is different forms of shell quoting. There is no "standard" for which to use. However, the 3 forms mean / do different things depending on the characters in the credential. Read the shell manual or a tutorial about what form of quoting is *needed*. – Stephen C Dec 11 '19 at 22:17
  • The second one's invalid cause of the spaces. Maybe you meant `export DB_USER=aodhfoi2`? – wjandrea Dec 11 '19 at 22:31
  • It would be helpful if you indicated in your question what these credentials are for. The name `DB_USER` tends to imply some kind of database; you should say so explicitly. A lot of applications use credentials, and the practices for storing them can vary widely. – Keith Thompson Dec 11 '19 at 22:45
  • Possible duplicate of [Defining a variable with or without export](https://stackoverflow.com/q/1158091/608639). – jww Dec 11 '19 at 23:59
  • @KeithThompson these would be loaded in a python application with various DB or Email or Server credentials. – David542 Dec 12 '19 at 00:02
  • @David542: As I said, that information should be in the question. – Keith Thompson Dec 12 '19 at 00:10

1 Answers1

1

I don't think there's a standard way. It is anyway considered a good practice to keep the passwords in reserved separate files from the main script. E.g.:

# .secretfile mode 600 (only root can read/write the file)
export pass=fweios
echo "Use $pass"

Then in the main script you can source the .secretfile and unset the variable when finished using it.

# mainscript
. .secretfile
# use $pass
unset pass
lainatnavi
  • 1,453
  • 1
  • 14
  • 22