1

I have the following lines in my .ssh/config:

Host localhost
ProxyCommand none
Host n0*
ProxyCommand none

Host *
ProxyCommand corkscrew proxy.m.com 80 myserv 443 ~/.ssh/auth

i.e. for localhost and n0* ssh will not use the proxy, but for other hosts it will.

I got trapped several times know when I wanted to connect to other local machines, but couldn't connect because the proxy was active. There was no exception for them in ~/.ssh/config.

Is there away to echo an information to the command line, when the proxy is used? e.g.

$ ssh otherpc
  ---> using  ProxyCommand corkscrew proxy.m.com 80 myserv 443 ~/.ssh/auth
Password: 

I know that ssh -v is listing this line (along with many others):

debug1: Executing proxy command: exec corkscrew proxy.m.com 80 myserv 443 ~/.ssh/auth                                                                                                                                        

Is there less verbose way of displaying the proxy command used, helping me to avoid being trapped? Maybe a clever bash alias/function grepping ssh -v?

Warning: Don't write ssh() { ssh -v | grep Proxy}. I tried that too ... and accidently fork bombed me :P

  • what about ssh -oProxyCommand None otherpc ? – Archemar Sep 4 '14 at 10:06
  • If I typed that, I would be aware that the proxy is active. The point is, however, that I tend to forget the rules I set and can't figure out why I can't logon... – Sebastian Sep 4 '14 at 11:08
2

I suggest that you write a small wrapper corkscrew-wrapper containing something like:

#!/bin/sh
echo "Executing proxy command corkscrew ..." > /dev/tty
exec corkscrew "$@"

and use corkscrew-wrapper instead of corkscrew in the ProxyCommand line.

If you want to support execution by at or cron, the following should work:

#!/bin/sh

cmd() { echo "Executing proxy command corkscrew ..."; }

{ cmd > /dev/tty; } 2> /dev/null
[ $? -eq 0 ] || cmd >&2

exec corkscrew "$@"

Note: do not detect the availability of /dev/tty with the tty command because the terminal is not necessarily connected to the standard input.

  • excellent idea! (why didn't I think of this myself...?) Looks like it's working. I will not accept immediately in order to encourage alternatives answers. – Sebastian Sep 4 '14 at 11:05
  • Follow up question: when launching from cron, /dev/tty is not available. The command works nonetheless, but the warning line 2: /dev/tty: No such device or address appears. – Sebastian Sep 4 '14 at 11:23
  • 1
    @Sebastian I've completed my answer. You may also want to use >&2 in all cases, but /dev/tty may be more reliable when available (and the standard error may have been redirected). – vinc17 Sep 4 '14 at 11:55
  • Sir, you're a master and a teacher, and since I cannot upvote twice, I'll immediately accept your answer, despite my earlier claim. My sincere thanks! – Sebastian Sep 4 '14 at 12:08

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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