2005/05/31 SSH_CLIENT, SSH_CONNECTION (OpenSSH Variables)

OpenSSH sets several environment variables which can be useful. It's easy enough to see them: just type "set | grep SSH" at a command prompt./p>

If you connected by SSH, these should include SSH_ASKPASS, SSH_CLIENT, SSH_CONNECTION and SSH_TTY, which can give helpful information to scripts.

For example, if we wanted to log all ssh connections not coming from our local network, we might do something like this:


#!/bin/bash
# called from login scripts such as /etc/profile
if [ "${SSH_CLIENT%.*}" != "10.3.38" ]
 then 
 logger -t warn -p info.warn "$SSH_CLIENT connnection"
fi
 

See Loglevel if you don't know what "logger" does. The "${SSH_CLIENT%.*}" extracts the subnet from the $SSH_CLIENT variable by stripping everything from the last period to the end.



Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> 2005/05/31 SSH_CLIENT, SSH_CONNECTION (OpenSSH Variables)



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





The teaching of BASIC should be rated as a criminal offence: it mutilates the mind beyond recovery. (Edsger W. Dijkstra)





This post tagged:

SSH