Hacktricks-skills linux-environment-variables
How to manage, configure, and secure Linux environment variables. Use this skill whenever the user needs to set, modify, or understand environment variables on Linux systems, configure proxies, hide command history, manage SSL certificates, customize prompts, or troubleshoot variable inheritance issues. Trigger for any task involving export, unset, PATH, proxy settings, HISTCONTROL, or environment variable security.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/linux-hardening/linux-environment-variables/SKILL.MDLinux Environment Variables
A skill for managing Linux environment variables, including security hardening, proxy configuration, and system customization.
When to Use This Skill
Use this skill when you need to:
- Set or modify environment variables (global or local)
- Configure proxy settings for network tools
- Hide or control command history for security
- Manage SSL certificate paths
- Customize bash prompts (PS1)
- Debug variable inheritance issues
- Understand what common environment variables do
Core Concepts
Global vs Local Variables
Global variables are inherited by child processes:
export MYVAR="value" echo $MYVAR # Accessible in current session and children unset MYVAR # Remove the variable
Local variables only exist in the current shell:
LOCAL="value" echo $LOCAL # Only accessible here, not in child processes
Listing Variables
set # All variables (including local) env # Exported variables only printenv # Same as env cat /proc/$$/environ # Current process env cat /proc/$(python -c "import os; print(os.getppid())")/environ # Parent process env
Common Environment Variables
| Variable | Purpose |
|---|---|
| X display (usually ) |
| Preferred text editor |
| User's home directory |
| Computer hostname |
| Current language |
| Directories containing executables |
| Current working directory |
| Current shell path (e.g., ) |
| Terminal type (e.g., ) |
| Current username |
| Time zone |
Security & Hardening
Hiding Command History
Prevent commands from being saved to
~/.bash_history:
# Disable history file writing on session end export HISTFILESIZE=0 # Disable in-memory history export HISTSIZE=0 # Hide commands that start with a space export HISTCONTROL=ignorespace
Usage: Commands prefixed with a space won't be saved:
$ echo "this saves" $ echo "this does not save" # Note the leading space
Proxy Configuration
Set HTTP/HTTPS proxies:
export http_proxy="http://10.10.10.10:8080" export https_proxy="http://10.10.10.10:8080"
Set SOCKS proxy for all protocols:
export all_proxy="socks5h://10.10.10.10:1080"
Bypass proxy for specific hosts:
export no_proxy="localhost,127.0.0.1,.corp.local,10.0.0.0/8"
Note: Both lowercase and uppercase variants work (
http_proxy/HTTP_PROXY).
SSL Certificate Configuration
Point tools to custom CA certificates:
export SSL_CERT_FILE=/path/to/ca-bundle.pem export SSL_CERT_DIR=/path/to/ca-certificates
Customizing Your Prompt (PS1)
The
PS1 variable controls your bash prompt appearance. Common elements:
- username\u
- hostname\h
- current directory\w
-\$
for root,#
for users$
- command number\!
- date\d
- time\t
Example prompt:
export PS1="\u@\h:\w\$ "
Scripts
Use the bundled scripts for common tasks:
- Display all environment variables in a formatted tablescripts/list-variables.sh
- Configure history hiding for securityscripts/hide-history.sh
- Configure proxy settings with validationscripts/set-proxy.sh
Troubleshooting
Variable not persisting
If a variable disappears after closing the terminal, add it to your shell config:
echo 'export MYVAR="value"' >> ~/.bashrc source ~/.bashrc
Child process not seeing variable
Make sure you used
export:
# Wrong - child won't see this MYVAR="value" # Right - child will inherit export MYVAR="value"
PATH issues
Check if a command is in your PATH:
which command_name hash -r # Clear command hash cache
Best Practices
- Use
for variables child processes needexport - Set
for sensitive workHISTCONTROL=ignorespace - Validate proxy URLs before setting them
- Document custom variables in your shell config
- Use
to verify variables are set correctlyprintenv - Be careful with
modifications - they affect all commandsPATH