📘
Hacktricks
  • GitHub: Welcome to the page where you will find each trick/technique/whatev
  • About the author
  • Getting Started in Hacking
  • Pentesting Methodology
  • External Recon Methodology
  • Phishing Methodology
  • Exfiltration
  • Tunneling and Port Forwarding
  • Brute Force - CheatSheet
  • Search Exploits
  • shells
    • Shells (Linux, Windows, MSFVenom)
  • linux-unix
    • Checklist - Linux Privilege Escalation
    • Linux Privilege Escalation
    • Useful Linux Commands
    • Linux Environment Variables
  • macos
    • MacOS Security & Privilege Escalation
  • windows
    • Checklist - Local Windows Privilege Escalation
    • Windows Local Privilege Escalation
    • Active Directory Methodology
    • NTLM
    • Stealing Credentials
    • Authentication, Credentials, UAC and EFS
    • Basic CMD for Pentesters
    • Basic PowerShell for Pentesters
    • AV Bypass
  • mobile-apps-pentesting
    • Android APK Checklist
    • Android Applications Pentesting
    • iOS Pentesting Checklist
    • iOS Pentesting
  • pentesting
    • Pentesting Network
  • Stargazers
  • blob
    • master
      • hacktricks/LICENSE.md at master
  • network
    • Forks
  • Issues
  • Pull requests
  • Actions
  • Projects
  • GitHub: Welcome to the page where you will find each trick/technique/whatev
  • Build software better, together
  • Pulse
  • tree
    • Build software better, together
    • GitHub at 1e46f267c2ce5c79bb9a8a146f468f214419f708
    • master
      • .gitbook
        • hacktricks/.gitbook/assets at master
      • hacktricks/.github at master
      • a.i.-exploiting
        • hacktricks/a.i.-exploiting/bra.i.nsmasher-presentation at master
      • hacktricks/backdoors at master
      • hacktricks/blockchain at master
      • hacktricks/cloud-security at master
  • Branches
  • Releases
  • Commits
    • Commits
  • Commits
  • commit
    • GitBook: [master] one page modified@1e46f26
    • GitBook: [master] 3 pages and 6 assets modified@e741d40
    • Update FUNDING.yml@c7e5a37
    • GitBook: [master] one page modified@5b5b28a
    • GitBook: [master] 511 pages and one asset modified@73a4b96
Powered by GitBook
On this page
  • Global variables
  • Local variables
  • List current variables
  • Persistent Environment variables
  • Common variables
  • Interesting variables for hacking
  • HISTFILESIZE
  • HISTSIZE
  • http_proxy
  • https_proxy
  • PS1

Was this helpful?

  1. linux-unix

Linux Environment Variables

Global variables

The global variables will be inherited by child processes.

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

export MYGLOBAL="hello world"echo $MYGLOBAL 

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

You can remove a variable doing:

Local variables

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

LOCAL="my local"echo $LOCALunset LOCAL

List current variables

setenvprintenvcat /proc/$$/environcat /proc/`python -c "import os; print(os.getppid())"`/environ

Persistent Environment variables

Files that affect behavior of every user:

  • /etc/bash.bashrc : This file is read whenever an interactive shell is started (normal terminal) and all the commands specified in here are executed.

  • /etc/profile and /etc/profile.d/*: This file is read every time a user logs in. Thus all the commands executed in here will execute only once at the time of user logging in.

    • Example:

      /etc/profile.d/somescript.sh

      #!/bin/bashTEST=$(cat /var/somefile)export $TEST

Files that affect behavior for only a specific user:

  • ~/.bashrc : This file behaves the same way /etc/bash.bashrc file works but it is executed only for a specific user. If you want to create an environment for yourself go ahead and modify or create this file in your home directory.

  • ~/.profile, ~/.bash_profile, ~/.bash_login: These files are same as /etc/profile. The difference comes in the way it is executed. This file is executed only when a user in whose home directory this file exists, logs in.

Common 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.

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).

http_proxy

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

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

https_proxy

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

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

PS1

Change how your prompt looks.

Root:

Regular user:

One, two and three backgrounded jobs:

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

PreviousUseful Linux CommandsNextmacos

Last updated 3 years ago

Was this helpful?

Extracted from: and ​

From: ​

I have created (based on another, read the code).

here
here
https://geek-university.com/linux/common-environment-variables/
this one