diff for ssh/sftp/scp -j

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

diff for ssh/sftp/scp -j

Holger Mikolon
Hi tech@

at work I can ssh (hence cvs) to public servers only via a ProxyCommand
specified in /etc/ssh/ssh_config.

However, with the ProxyCommand set I cannot ssh into servers in the
internal network. So I end up changing ssh_config depending on my
use case over and over. This bothered me enough to come up with the
following simple diff. It adds a command line option -j to ssh/sftp/scp
for ignoring the ProxyCommand. Of course "-j" can be changed to any
other free letter.

Anyone else finding this useful? Comments?

Regards
Holger
;-se


Index: usr.bin/ssh/scp.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/scp.c,v
retrieving revision 1.193
diff -u -p -u -r1.193 scp.c
--- usr.bin/ssh/scp.c 21 Oct 2017 23:06:24 -0000 1.193
+++ usr.bin/ssh/scp.c 25 Nov 2017 21:59:05 -0000
@@ -400,7 +400,7 @@ main(int argc, char **argv)
  addargs(&args, "-oClearAllForwardings=yes");
 
  fflag = tflag = 0;
- while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
+ while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:jP:q12346S:o:F:")) != -1)
  switch (ch) {
  /* User-visible flags. */
  case '1':
@@ -426,6 +426,9 @@ main(int argc, char **argv)
  addargs(&remote_remote_args, "%s", optarg);
  addargs(&args, "-%c", ch);
  addargs(&args, "%s", optarg);
+ break;
+ case 'j':
+ addargs(&args, "-j");
  break;
  case 'P':
  sshport = a2port(optarg);
Index: usr.bin/ssh/sftp.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/sftp.c,v
retrieving revision 1.182
diff -u -p -u -r1.182 sftp.c
--- usr.bin/ssh/sftp.c 3 Nov 2017 03:46:52 -0000 1.182
+++ usr.bin/ssh/sftp.c 25 Nov 2017 21:59:05 -0000
@@ -2303,7 +2303,7 @@ main(int argc, char **argv)
  infile = stdin;
 
  while ((ch = getopt(argc, argv,
-    "1246afhpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) {
+    "1246afhpqrvCc:D:i:jl:o:s:S:b:B:F:P:R:")) != -1) {
  switch (ch) {
  /* Passed through to ssh(1) */
  case '4':
@@ -2318,6 +2318,9 @@ main(int argc, char **argv)
  case 'o':
  addargs(&args, "-%c", ch);
  addargs(&args, "%s", optarg);
+ break;
+ case 'j':
+ addargs(&args, "-j");
  break;
  case 'q':
  ll = SYSLOG_LEVEL_ERROR;
Index: usr.bin/ssh/ssh.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/ssh.c,v
retrieving revision 1.469
diff -u -p -u -r1.469 ssh.c
--- usr.bin/ssh/ssh.c 1 Nov 2017 00:04:15 -0000 1.469
+++ usr.bin/ssh/ssh.c 25 Nov 2017 21:59:05 -0000
@@ -583,7 +583,7 @@ main(int ac, char **av)
  argv0 = av[0];
 
  again:
- while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
+ while ((opt = getopt(ac, av, "1246ab:c:e:fgi:jkl:m:no:p:qstvx"
     "ACD:E:F:GI:J:KL:MNO:PQ:R:S:TVw:W:XYy")) != -1) {
  switch (opt) {
  case '1':
@@ -626,6 +626,9 @@ main(int ac, char **av)
  break;
  case 'g':
  options.fwd_opts.gateway_ports = 1;
+ break;
+ case 'j':
+ options.proxy_command = xstrdup("none");
  break;
  case 'O':
  if (options.stdio_forward_host != NULL)

Reply | Threaded
Open this post in threaded view
|

Re: diff for ssh/sftp/scp -j

Sebastian Benoit-3
Holger Mikolon([hidden email]) on 2017.11.25 23:16:54 +0100:

> Hi tech@
>
> at work I can ssh (hence cvs) to public servers only via a ProxyCommand
> specified in /etc/ssh/ssh_config.
>
> However, with the ProxyCommand set I cannot ssh into servers in the
> internal network. So I end up changing ssh_config depending on my
> use case over and over. This bothered me enough to come up with the
> following simple diff. It adds a command line option -j to ssh/sftp/scp
> for ignoring the ProxyCommand. Of course "-j" can be changed to any
> other free letter.
>
> Anyone else finding this useful? Comments?

well, you could also just have two config files and use

  ssh -F $HOME/.ssh/config_with_proxy

and since thats too long to type

  alias sshp="ssh -F $HOME/.ssh/config_with_proxy"

imho not worth yet another option.

/Benno

 

> Regards
> Holger
> ;-se
>
>
> Index: usr.bin/ssh/scp.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ssh/scp.c,v
> retrieving revision 1.193
> diff -u -p -u -r1.193 scp.c
> --- usr.bin/ssh/scp.c 21 Oct 2017 23:06:24 -0000 1.193
> +++ usr.bin/ssh/scp.c 25 Nov 2017 21:59:05 -0000
> @@ -400,7 +400,7 @@ main(int argc, char **argv)
>   addargs(&args, "-oClearAllForwardings=yes");
>  
>   fflag = tflag = 0;
> - while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
> + while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:jP:q12346S:o:F:")) != -1)
>   switch (ch) {
>   /* User-visible flags. */
>   case '1':
> @@ -426,6 +426,9 @@ main(int argc, char **argv)
>   addargs(&remote_remote_args, "%s", optarg);
>   addargs(&args, "-%c", ch);
>   addargs(&args, "%s", optarg);
> + break;
> + case 'j':
> + addargs(&args, "-j");
>   break;
>   case 'P':
>   sshport = a2port(optarg);
> Index: usr.bin/ssh/sftp.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ssh/sftp.c,v
> retrieving revision 1.182
> diff -u -p -u -r1.182 sftp.c
> --- usr.bin/ssh/sftp.c 3 Nov 2017 03:46:52 -0000 1.182
> +++ usr.bin/ssh/sftp.c 25 Nov 2017 21:59:05 -0000
> @@ -2303,7 +2303,7 @@ main(int argc, char **argv)
>   infile = stdin;
>  
>   while ((ch = getopt(argc, argv,
> -    "1246afhpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) {
> +    "1246afhpqrvCc:D:i:jl:o:s:S:b:B:F:P:R:")) != -1) {
>   switch (ch) {
>   /* Passed through to ssh(1) */
>   case '4':
> @@ -2318,6 +2318,9 @@ main(int argc, char **argv)
>   case 'o':
>   addargs(&args, "-%c", ch);
>   addargs(&args, "%s", optarg);
> + break;
> + case 'j':
> + addargs(&args, "-j");
>   break;
>   case 'q':
>   ll = SYSLOG_LEVEL_ERROR;
> Index: usr.bin/ssh/ssh.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ssh/ssh.c,v
> retrieving revision 1.469
> diff -u -p -u -r1.469 ssh.c
> --- usr.bin/ssh/ssh.c 1 Nov 2017 00:04:15 -0000 1.469
> +++ usr.bin/ssh/ssh.c 25 Nov 2017 21:59:05 -0000
> @@ -583,7 +583,7 @@ main(int ac, char **av)
>   argv0 = av[0];
>  
>   again:
> - while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx"
> + while ((opt = getopt(ac, av, "1246ab:c:e:fgi:jkl:m:no:p:qstvx"
>      "ACD:E:F:GI:J:KL:MNO:PQ:R:S:TVw:W:XYy")) != -1) {
>   switch (opt) {
>   case '1':
> @@ -626,6 +626,9 @@ main(int ac, char **av)
>   break;
>   case 'g':
>   options.fwd_opts.gateway_ports = 1;
> + break;
> + case 'j':
> + options.proxy_command = xstrdup("none");
>   break;
>   case 'O':
>   if (options.stdio_forward_host != NULL)
>

Reply | Threaded
Open this post in threaded view
|

Re: diff for ssh/sftp/scp -j

Jiri B-2
In reply to this post by Holger Mikolon
On Sat, Nov 25, 2017 at 11:16:54PM +0100, Holger Mikolon wrote:

> Hi tech@
>
> at work I can ssh (hence cvs) to public servers only via a ProxyCommand
> specified in /etc/ssh/ssh_config.
>
> However, with the ProxyCommand set I cannot ssh into servers in the
> internal network. So I end up changing ssh_config depending on my
> use case over and over. This bothered me enough to come up with the
> following simple diff. It adds a command line option -j to ssh/sftp/scp
> for ignoring the ProxyCommand. Of course "-j" can be changed to any
> other free letter.
>
> Anyone else finding this useful? Comments?
>
> Regards
> Holger
> ;-se

Wouldn't help you just use wildcards for Host in ssh_config and/or
CanonicalizeHostname?

Jiri

Reply | Threaded
Open this post in threaded view
|

Re: diff for ssh/sftp/scp -j

Holger Mikolon
In reply to this post by Sebastian Benoit-3
> Date: Sun, 26 Nov 2017 02:09:13
> From: Sebastian Benoit <[hidden email]>
> To: Holger Mikolon <[hidden email]>
> Cc: [hidden email]
> Subject: Re: diff for ssh/sftp/scp -j
>
> Holger Mikolon([hidden email]) on 2017.11.25 23:16:54 +0100:
> > Hi tech@
> >
> > at work I can ssh (hence cvs) to public servers only via a ProxyCommand
> > specified in /etc/ssh/ssh_config.
> >
> > However, with the ProxyCommand set I cannot ssh into servers in the
> > internal network. So I end up changing ssh_config depending on my
> > use case over and over. This bothered me enough to come up with the
> > following simple diff. It adds a command line option -j to ssh/sftp/scp
> > for ignoring the ProxyCommand. Of course "-j" can be changed to any
> > other free letter.
> >
> > Anyone else finding this useful? Comments?
>
> well, you could also just have two config files and use
>
>   ssh -F $HOME/.ssh/config_with_proxy
>
> and since thats too long to type
>
>   alias sshp="ssh -F $HOME/.ssh/config_with_proxy"
>
> imho not worth yet another option.
>
> /Benno

Thanks Benno, Stuart and Jiri for your responses.

An alias doesn't work with cvs over ssh, at least not when I do:
   $ alias sshp="ssh -F $HOME/.ssh/config_with_proxy"
   $ export CVS_RSH=sshp"
   $ cvs up

CVS_RSH doesn't like flags/parameters either. I haven't figured out
a way to pass ssh flags to cvs (via CVS_RSH), except by creating a
simple script /usr/local/bin/sshp which calls ssh with my favorite
flags.

I have used various ssh_config setups with and without domain specific
blocks but never came to a config that worked everywhere (likely my
fault). On top of that I use my OpenBSD laptop at work (proxy needed)
and as well at home (no proxy needed for the exact same destination).

So I will continue with custom scripts (or aliases for the non-cvs
cases). No big deal.

Regards,
Holger
;-se