vote up 1 vote down star

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

flag

5 Answers

vote up 2 vote down check

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|flag
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 at 18:39
vote up 7 vote down

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|flag
vote up 1 vote down

I like the "w" answer,

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

hostname
link|flag
vote up 1 vote down

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|flag
vote up 0 vote down

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|flag

Your Answer

Get an OpenID
or
never shown

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