his is a quick tip if you use an xserver that is running remotely and you want to set the DISPLAY environment variable when you login to the machine using ssh. It is actually very simple to do.

When you use ssh it will automatically set the SSH_CLIENT environment variable to contain the client connection details eg the ip address port number etc.. to get this to work you will need to paste the following into your .bashrc file.

if [ ! $DISPLAY ] ; then
        if [ "$SSH_CLIENT" ] ; then
                export DISPLAY=`echo $SSH_CLIENT|cut -f1 -d\ `:0.0

the above will check that the DISPLAY environment variable is not currently set and that the SSH_CLIENT variable is set. It will then extract the ip address from SSH_CLIENT

Last Modified: 12 December 2016

Releated Posts

2013-03-01 - Linux - What and how to kill a zombie process
2013-02-14 - Linux - Getting sshfs to work
2012-12-12 - Linux - List / Copy group membership for users
2012-12-08 - Linux - ssh key authentication
2012-12-04 - Linux - sudo without a password
2012-10-13 - Rasberry Pi - Alternative method to play video without omx gstreamer element
2012-10-10 - How to run tcpdump as root
2012-07-13 - Linux - Killing all processes for a specific user
2012-04-05 - Using gdb to debug a core file
2012-01-16 - Linux - Color Coding The Bash Prompt
2012-01-14 - Linux - Automatically set the DISPLAY environment variable in SSH connection
2012-01-06 - Adding extra swap space to linux