SSH: Where did I come from?

When you are frequently hopping between SSH hosts in different shells, you may forget which nodes you went through to actually get to the host you are on now. With the following changes, you can extend your bash prompt to show any intermediate hosts you went trough:

For this to work, add the following code to your .bashrc file:

Then, add the variable $HCHAIN into your PS1 environment variable. The output shown above can be achieved by

As long as you do this on all machines you are moving across, then arbitrary hops are recorded correctly.

Leave a comment

Your email address will not be published.