You are not logged in.

#1 2009-12-07 06:34:31

Yaro
Member
Registered: 2009-04-03
Posts: 154

SSH check?

Is there a way to, in a BASH script, check to see if the current session is SSH vs. local at all?

Offline

#2 2009-12-07 06:45:21

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: SSH check?

There is probably something in the environment. Mine gives:

$ env | grep SSH_
SSH_CLIENT=10.0.0.2 42836 22
SSH_TTY=/dev/pts/0
SSH_CONNECTION=10.0.0.2 42836 10.0.0.1 22

Not sure if this is standard or dependent on the client/server implementation.

Offline

#3 2009-12-07 06:46:28

jowilkin
Member
Registered: 2009-05-07
Posts: 243

Re: SSH check?

I don't know if this always works, but I think you can check to see if the SSH_CONNECTION variable is set. (edit: Mike beat me to it smile )

You can also check to see if the DISPLAY variable is set to see if the session was started from X.

Last edited by jowilkin (2009-12-07 06:49:24)

Offline

#4 2009-12-07 18:02:38

Yaro
Member
Registered: 2009-04-03
Posts: 154

Re: SSH check?

Thanks for the help. I used the SSH_TTY environment variable to carry out the test with a simple if statement:

if [ $SSH_TTY ];

It works.

Offline

Board footer

Powered by FluxBB