How can I tell if I'm ssh'd into a host?

Giorgos Keramidas keramida at ceid.upatras.gr
Sun Aug 22 17:46:17 PDT 2004


On 2004-08-22 15:41, Gary Kline <kline at tao.thought.org> wrote:
>
> This is a strange one.  On different hosts in my ~/.zlogin, I test for
> `hostname` = HOST.thought.org
>
> If true, I do certain things such as set xhost FOO and xmodmap
> ~/.xmodmaprc...  I've noticed that with my 5-CURRENT on my laptop,
> I get complains from xhost and naturally, xmodmap.
>
> Is there a way of asking where I am on the console/KVM, or remote and
> ssh'd?  Sorry if I''m not explaining this well.  --I didn't notice
> these complains when I had 4.10 on my laptop.  Aside from having
> .zlogin prompt: "Are you ssh'd in? [y/[n]] " I'm drawing a blank.

$ env | grep SSH
SSH_CLIENT=212.205.244.189 64903 22
SSH_TTY=/dev/pts/0
SSH_CONNECTION=212.205.244.189 64903 62.1.205.36 22

If SSH_CONNECTION is set, you can bet you're ssh'ed into a host.

As a small extra tip, I use this as a local hack in the .bashrc file of
the root user in my company's servers, to add customizations that apply
only when an incoming ssh connection from my personal workstation is
detected:

if [ X$( echo ${SSH_CONNECTION} | awk '{print $1}' ) = X"10.0.0.X" ]; then
    # Customizations SSH connections originating at my workstation.
    # - Giorgos Keramidas
    source ~/.bashrc.keramida
fi



More information about the freebsd-questions mailing list