Server Fault is a question and answer site for system and network administrators. 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

I have three machines A,B,C. If I ssh into B from A, then into C from B, how can I find the path A->B->C ?

I'd like to display this information in the prompt in order to know where I'm going to land when I exit ssh .

share|improve this question

You can look at ssh connections with lsof and try to figure out where are you connected from right now.

For example:

lsof -i:ssh
root@prmox01:~# lsof -i:ssh
sshd     1404 root    3u  IPv4   9601      0t0  TCP *:ssh (LISTEN)
sshd     1404 root    4u  IPv6   9603      0t0  TCP *:ssh (LISTEN)
sshd    66653 root    3r  IPv4 167143      0t0  TCP> (ESTABLISHED)
share|improve this answer
This would work if I could set a remote variable when I ssh into the machine, otherwise I will only get the last hop of the path, but I want the whole path (A->B->C) – alecail Aug 4 '12 at 10:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.