[lug] auto set DISPLAY variable from ssh login?
Jeff Schroeder
jeff at zingstudios.net
Sun Sep 24 15:22:56 MDT 2006
> Does anyone know if there is a way to automate setting of DISPLAY
> based on the remote IP of an ssh text login? And better yet, to do so
> only for certain IP addresses?
From what I can tell, when you login to a remote server via SSH, a few
environment variables are set:
# env | grep SSH
SSH_CLIENT=192.168.1.107 52876 22
SSH_TTY=/dev/ttyp1
SSH_CONNECTION=192.168.1.107 52876 192.168.1.100 22
In the example above, I've logged into 192.168.1.100 from 192.168.1.107.
You can see those addresses in the SSH_CONNECTION variable.
Thus, to answer your question, you could put something into your .bashrc
(or .cshrc, etc.) that would set DISPLAY for you:
remote_ip=$(echo $SSH_CLIENT | awk '{ print $1 }')
export DISPLAY=$remote_ip:0.0
This would redirect the display to the client machine (I do this myself,
so I can run X apps on a remote machine but display them locally). You
mentioned that you only want to do this for certain IP addresses, so
you could then add some logic:
if [ "$remote_ip" == "192.168.1.107" ]; then
export DISPLAY=$remote_ip:0.0
fi
Adjust as needed.
HTH,
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20060924/cab679ac/attachment.pgp>
More information about the LUG
mailing list