Linux Environment Variables
Last updated
Was this helpful?
Last updated
Was this helpful?
Become VeryLazyTech ! πComment
Follow us on:
β Twitter .Comment
πΎ Github .Comment
π Medium .Comment
πΊ YouTube .Comment
π© Telegram .Comment
π΅οΈββοΈ My Site .Comment
CommentComment
Visit our for e-books and courses. πComment
Support us and . β
In a Linux operating system, environment variables are dynamic values that define the behavior of system processes and applications. These variables store configuration data, such as the system path, user preferences, and settings, making them essential for efficient system operations and automation.
These are available for all users and are set by the system administrator. They are defined in files such as:
/etc/environment
/etc/profile
/etc/bash.bashrc
These are defined per user and stored in:
~/.bashrc
~/.profile
~/.bash_profile
Shell variables exist only within the running shell session. They can be created and modified within the terminal.
PATH
The PATH
variable defines directories where the system searches for executable files.
HOME Represents the home directory of the current user.
USER Stores the username of the logged-in user.
SHELL Specifies the default shell of the user.
EDITOR Defines the default text editor.
LANG Sets the system language.
DISPLAY Specifies the display used by the X Window System.
HISTFILESIZE Sets the maximum number of lines contained in the history file.
HISTSIZE Defines the number of lines added to the history file per session.
HOSTNAME Stores the hostname of the computer.
MAIL Specifies the location of the userβs mail spool.
MANPATH Defines the list of directories to search for manual pages.
OSTYPE Indicates the type of operating system.
PS1 Defines the default Bash prompt.
PWD Stores the current working directory.
TERM
Specifies the current terminal type (e.g., xterm
, linux
).
TZ Sets the time zone.
printenv
Commandenv
Commandset
CommandThis variable will be available only for the current session.
To make a variable persistent, add it to ~/.bashrc
or ~/.profile
.
To remove an environment variable:
Environment variables are often used in Bash scripting to automate tasks.
Example script:
Save this as script.sh
, then execute:
Avoid Storing Sensitive Data: Never store passwords in environment variables.
Use readonly
for Critical Variables:
Restrict Access to Environment Files:
Change the value of this variable to 0, so when you end your session the history file (~/.bash_history) will be deleted.
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).
The processes will use the proxy declared here to connect to internet through http or https.
The processes will trust the certificates indicated in these env variables.
LD_PRELOAD Allows injecting shared libraries into running processes, often used for privilege escalation or bypassing security measures.
LD_LIBRARY_PATH Defines directories where the dynamic linker searches for shared libraries, which can be used for hijacking.
PATH Manipulation
Adding a malicious directory to PATH
can be used for command hijacking.
TMOUT Automatically logs out an idle user, useful for clearing sessions quickly.
XDG_CONFIG_HOME Can be used to control where applications store configuration files, potentially allowing manipulation.
IFS (Internal Field Separator)
Modifying IFS
can be used to change command parsing behavior in scripts.
PS1 Manipulation Modify the prompt to hide the current user or create deception.
HOME
Change HOME
to manipulate where programs store configurations or execute files.
MAIL Modify the mail spool directory to read or redirect emails.
SUDO_ASKPASS
Trick sudo
into using a fake prompt to steal passwords.
GDBINIT Define a malicious GDB startup file to execute arbitrary commands.
Learn & practice
Become VeryLazyTech ! π
β Twitter .
πΎ Github .
π Medium .
πΊ YouTube .
π© Telegram .
π΅οΈββοΈ My Site .
Visit our for e-books and courses. π
Support us and . β