APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

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

© May 2005 Tony Lawrence

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:

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

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)

Inexpensive and informative Apple related e-books:

Take Control of OS X Server

Take Control of Upgrading to El Capitan

Take Control of iCloud

Are Your Bits Flipped?

Digital Sharing Crash Course

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

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

Printer Friendly Version

The worst crime against working people is a company which fails to operate at a profit. (Samuel Gompers)

Linux posts

Troubleshooting posts

This post tagged:




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode