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 there an easy way to tell if I am SSH'd in somewhere without typing 'exit'?

Like, if I am currently sitting at computer A and I SSH'd to computer B and then from B to computer C, is there a way I would be able to tell short of closing the session and using 'hostname' to discover where I am at?

(Presumably, this solution would also make it clear that I am not SSH'd anywhere, if I am just at localhost but if I am SSH'd elsewhere and from there SSH'd back to my local machine, I'd be able to tell.)

share|improve this question
up vote 3 down vote accepted

Check out $SSH_CONNECTION. It tells you which IP and port you are currently connecting from and to. At least, this is the case with OpenSSH. YMMV with other servers.

share|improve this answer

If you know you are 'ssh'ed, but don't know from where, try


at a command-line. The output includes a FROM field which may be useful.

share|improve this answer

Try setting your prompt to include the hostname; otherwise I like to use screen on every login with a status line containing the hostname (a bit complicated to setup, and it gets recursive with status lines within screens with status lines). You should be able to echo $HOSTNAME or just execute hostname.

share|improve this answer
Not as fun to set up but with the amount of machines I need to get to, I think it's time I just started using screen. :-). – briealeida Nov 15 '09 at 18:39

I like the "w" answer,

and another way is to check the hostname to find out what the computers name is:

share|improve this answer

In your scenario, connect directly from A to C, if this is possible. This will avoid the double encryption. And perhaps will increase latency.

Also modify the shell variable PS1 for every account to reflect the hostname, if it doesn't do it yet. This trick will also help you in situations when you use chroot.

share|improve this answer

You must log in to answer this question.

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