up vote 1 down vote favorite
share [g+] share [fb]

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.)

link|improve this question
feedback

5 Answers

up vote 3 down vote accepted

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.

link|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
feedback

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

w

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

link|improve this answer
feedback

I like the "w" answer,

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

hostname
link|improve this answer
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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