Skip to content

Linux Environment Variables โ€‹

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks:

Try Hard Security Group

โ›“๏ธ External Link

Global variables โ€‹

The global variables will be inherited by child processes.

You can create a global variable for your current session doing:

bash
export MYGLOBAL="hello world"
echo $MYGLOBAL #Prints: hello world

This variable will be accessible by your current sessions and its child processes.

You can remove a variable doing:

bash
unset MYGLOBAL

Local variables โ€‹

The local variables can only be accessed by the current shell/script.

bash
LOCAL="my local"
echo $LOCAL
unset LOCAL

List current variables โ€‹

bash
set
env
printenv
cat /proc/$$/environ
cat /proc/`python -c "import os; print(os.getppid())"`/environ

Common variables โ€‹

From: https://geek-university.com/linux/common-environment-variables/

  • DISPLAY โ€“ the display used by X. This variable is usually set to :0.0, which means the first display on the current computer.
  • EDITOR โ€“ the userโ€™s preferred text editor.
  • HISTFILESIZE โ€“ the maximum number of lines contained in the history file.
  • HISTSIZE โ€“ Number of lines added to the history file when the user finish his session
  • HOME โ€“ your home directory.
  • HOSTNAME โ€“ the hostname of the computer.
  • LANG โ€“ your current language.
  • MAIL โ€“ the location of the userโ€™s mail spool. Usually /var/spool/mail/USER.
  • MANPATH โ€“ the list of directories to search for manual pages.
  • OSTYPE โ€“ the type of operating system.
  • PS1 โ€“ the default prompt in bash.
  • PATH โ€“ stores the path of all the directories which holds binary files you want to execute just by specifying the name of the file and not by relative or absolute path.
  • PWD โ€“ the current working directory.
  • SHELL โ€“ the path to the current command shell (for example, /bin/bash).
  • TERM โ€“ the current terminal type (for example, xterm).
  • TZ โ€“ your time zone.
  • USER โ€“ your current username.

Interesting variables for hacking โ€‹

HISTFILESIZE โ€‹

Change the value of this variable to 0, so when you end your session the history file (~/.bash_history) will be deleted.

bash
export HISTFILESIZE=0

HISTSIZE โ€‹

Change the value of this variable to 0, so when you end your session any command will be added to the history file (~/.bash_history).

bash
export HISTSIZE=0

http_proxy & https_proxy โ€‹

The processes will use the proxy declared here to connect to internet through http or https.

bash
export http_proxy="http://10.10.10.10:8080"
export https_proxy="http://10.10.10.10:8080"

SSL_CERT_FILE & SSL_CERT_DIR โ€‹

The processes will trust the certificates indicated in these env variables.

bash
export SSL_CERT_FILE=/path/to/ca-bundle.pem
export SSL_CERT_DIR=/path/to/ca-certificates

PS1 โ€‹

Change how your prompt looks.

This is an example

Root:

Regular user:

One, two and three backgrounded jobs:

One background job, one stopped and last command didn't finish correctly:

Try Hard Security Group

โ›“๏ธ External Link
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks: