I am not so into Linux and I have the following problem related to how permanentlyunset some environment variables.
The problem is that each time that I log into my system, performing the env command I obtain some variables that I have to permanently remove, in particular:
my.username@VHCLWSO2AS02:~$ env
..........................................
HTTP_PROXY=
HTTPS_PROXY=
http_proxy=
https_proxy=
.........................................
.........................................
.........................................these for variables related to proxy have to be permanently removed (for all the users, also for the root user) and I am not sure how to do it.
The .profile file inside the logged user home direcoty contains:
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH"
fiI can't see environment variales declaration inside this file.
The .bashrc file inside the logged user home directory contains:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'$
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi
fiThe /etc/environment file should contain evironmnet variables declaration that affect the system as a whole (rather than just a particular user) contains:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
#http_proxy=
#https_proxy=
#HTTP_PROXY=
#HTTPS_PROXY=This contains my variables definition, I commented out these variables to permanently unset them some times ago. I never restarted the system because it is a server and I can't do it. I am not sure that this no restart situation can be the cause of my problem (I can just log out the session).
Why I still obtain these variable each time that I log again into my system via SSH? What have I to do to permanently delete these variables? What am I missing?
61 Answer
The unset command can be used in order to completely erase the existence of an environment variable
No, unset cannot permanently remove environment variables, much like export does not permanently set them either, because there is simply no such thing as a "permanent" environment in the first place – it is always assembled anew by login processes and scripts.
(All environment variables are per-process and copied all the way down from your login process to all programs. However, changes are never copied up from child to parent.)
Both the export and unset commands only alter the environment of the current process (i.e. the 'bash' shell) that they're being run in, and it's all about where you place those commands that makes their effects "permanent" or not. For example, if you put such commands in ~/.profile they will be executed during every login, and therefore will appear to be permanent.
I never restarted the system because it is a server and I can't do it. I am not sure that this no restart situation can be the cause of my problem (I can just log out the session).
Why I still obtain these variable each time that I log again into my system via SSH? What have I to do to permanently delete these variables? What am I missing?
It is possible that not restarting is the problem. For example, if the variables were once set by /etc/environment, it could be that they were also set for the main process that accepts your logins, and therefore inherited all the way down when that process start your login shells.
However, this should not be an issue with SSH, since sshd always clears its environment for each connection. Look for other sources instead:
Make sure the envvars aren't being set by
/etc/profileor/etc/profile.d/*.sh.Make sure they're not being set by
/etc/bash.bashrceither.Check for
~/.pam_environment, which is a special configuration file read before the shell even starts.If you use Bash, check
~/.bash_profileand~/.bash_login– if either of those files exists, it takes priority and the "general" ~/.profile is completely ignored.Check for
~/.ssh/environment,~/.ssh/rc, and other files in that location.Run a search with
grep -r HTTP_PROXY /etcto uncover other possible hidden places.
Finally, if nothing else works, placing unset HTTP_PROXY in your profile script will cause it to remove the variables every time you log in, making the effect somewhat permanent.