Objective. Students will apply layered credential-management techniques—environment files, .pgpass, Oracle wallets, restricted file permissions, and secrets scanning—to eliminate plaintext passwords from all scripts in their automation library.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Every time a password appears in a shell script, it is readable by anyone who can view that file, inspect process environment variables, or read shell history logs. In a database environment, a compromised credential can expose entire schemas, customer records, and backups. Professional database administrators treat credential exposure as a high-severity vulnerability—not merely bad style.
This lesson applies layered controls to eliminate plaintext passwords from your Bash automation library. The same defense-in-depth philosophy used in physical security—never relying on a single lock—applies here: no single technique is foolproof, so you combine several.
A `.env` file stores key-value pairs such as `DB_PASS=secret` outside of the script itself. The script sources the file at runtime with `source /path/to/.env` or `. /path/to/.env`. The critical step is setting the file's permissions so only the owning user can read or write it:
```bash
chmod 0600 ~/.env
```
Mode `0600` means owner read/write, no access for group or others. Store the `.env` file outside version-control directories and add it to `.gitignore`. Never commit it to a repository.
Always validate that the file exists and is not world-readable at the top of every script that sources it:
```bash
[ "$(stat -c '%a' ~/.env)" = "600" ] || { echo "Bad .env permissions"; exit 1; }
. ~/.env
```
PostgreSQL's `.pgpass` file (`~/.pgpass` on Linux) stores connection credentials in the format `hostname:port:database:username:password`. The `libpq` library reads this file automatically when no password is supplied on the command line. Required permissions:
```bash
chmod 0600 ~/.pgpass
```
If permissions are wider than `0600`, PostgreSQL ignores the file entirely.
For stronger authentication, configure `pg_hba.conf` to require `scram-sha-256` instead of `md5` or `trust`:
```
host all dbauser 127.0.0.1/32 scram-sha-256
```
For certificate-based authentication (the strongest client-auth method), use the `cert` method in `pg_hba.conf` and supply a client certificate signed by the server's CA. No password travels over the network at all. Your backup script can then call `pg_dump` without any credential flag—the certificate and private key handle identity.
Oracle Database uses an encrypted wallet (managed with `mkstore` or the ORAPKI utility) to store connection credentials. The `sqlplus /@TNS_ALIAS` syntax instructs SQLPlus to retrieve the password from the wallet rather than accepting it as an argument. The wallet directory must be protected:
```bash
chmod 0700 /path/to/wallet
```
Oracle's wallet approach aligns directly with the Oracle DBA CA exam's security domain, which expects candidates to know how to avoid embedding passwords in scripts and connection strings.
Before committing or deploying any script, run a grep scan across your automation library:
```bash
grep -rn 'password\|PASSWORD\|PGPASSWORD' ./scripts/
```
A clean library returns zero hits. This is a mandatory gate in this lesson: if the scan finds anything, refactor before moving on. In professional pipelines this scan is automated—tools such as `git-secrets` or `truffleHog` run at commit time. For this course, the manual `grep` scan achieves the same learning goal.
Beyond credential management, harden every script with these header directives:
OSHA's Lockout/Tagout (LOTO) standard (29 CFR 1910.147) requires workers to isolate and de-energize equipment before servicing it, so that no one else can accidentally re-energize it during the work. The database equivalent is least-privilege service accounts: a backup service account should have `SELECT` and `pg_dump` rights only—not `SUPERUSER`. If that account is compromised, the blast radius is limited, just as LOTO limits injury risk to the worker performing maintenance.
Additional physical controls that complement digital script security include:
Completing the OSHA security checklist in this lesson connects these principles explicitly so you can explain digital security decisions in physical-safety language—a skill valued in team environments where not everyone has a technical background.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.