Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get the users ip address, domain name, or host-name of an established ssh connection in the shell? For example, when I connect over ssh the first printed line says something like this:

Last Login: Sat Fri 17 19:00:00 2012 from some.website.net

Is there an environment variable created or a way to access some.website.net or the ip address of the connected client. Preferably I would want some.website.net, but I might be able to make do with an ip address.

For your information, I plan to use this in order to automatically select the appropriate .tmux.conf file so that the statusline is less busy and can accommodate a smaller resolution screen i.e. a smartphone screen.

-- further details:

I am particularly interested in using this on an OSX computer, but it would be nice to have an OS independent solution.

share|improve this question

I'm not sure what distribution you're on, so this might not apply to you. I use CentOS, which maintains a record in /var/log (your system probably has one, but it might be somewhere else).

Try:

cat /var/log/lastlog

Which returns (example):

2¤?Opts/05xxxxxxd7.bb.xxxxxx.com
share|improve this answer
    
Thanks for that, it will help in some instances such as OpenSUSE, which has this log (though it seems to spit out a lot of garbage, too), but I am currently interested in OSX which is a variant of BSD. Unfortunately, this is not a log file in OSX. – scicalculator Feb 18 '12 at 13:39
    
OSX records similar information to the lastlog file in the Apple Syslog. Check the files under /var/log/asl and see if you can find what you're looking for (I'm afraid I don't use OSX here). – Josh Feb 18 '12 at 13:45
    
thanks for that, but it seems these files are binary log files and are difficult to parse. Using cat spills a lot of junk to the screen and parsing it would be a pain, although they interestingly seem to have logs for each day of the past week. I'll investigate if there is a good way to use it. – scicalculator Feb 18 '12 at 14:33
    
Good luck, anyhow. What you need is in there somewhere ;) – Josh Feb 18 '12 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .