I have a remote server and I am writing a script in the server and want it to fire only when I SSH. I thought of using the $SSH_CONNECTION and $SSH_TTY for this purpose. I found out that when I have not used ssh and instead used my VNC client to get into the server ( I have vnc running on my server), the terminals created within VNC still have these two environment variables set and $SSH_CONNECTION has same value in both cases.I found a workaround to do further filtering by ps -o comm= -p $PPID and see if parent process is sshd but I want to know why the variables are set
Linux: $SSH_CONNECTION is set even without SSHing to the server
linux;bash;ssh;bashrc;sshd
Why are the SSH variables set?It is likely that the variables are set because your VNC connection is tunneled through an SSH connection.  There are good reasons to do this.  VNC uses the RFB protocol which is not secure.  Tunneling VNC through SSH improves security.Why is the SSH_CONNECTION variable the same?The SSH_CONNECTION variable consists of four values: (1) client IP address, (2) client port number, (3) server IP address, and (4) server port number.  For a particular client talking to a particular server, the only one of those that is likely to change from one session to the next is the client port number.  Whether it changes depends.  For example, SSH can be instructed to reuse existing connections.  This is done for speed.  If so, then several connections may all share one port.