About Archive Tags RSS Feed

 

Patching scp and other updates.

8 January 2017 21:50

I use openssh every day, be it the ssh command for connecting to remote hosts, or the scp command for uploading/downloading files.

Once a day, or more, I forget that scp uses the non-obvious -P flag for specifying the port, not the -p flag that ssh uses.

Enough is enough. I shall not file a bug report against the Debian openssh-client page, because no doubt compatibility with both upstream, and other distributions, is important. But damnit I've had enough.

apt-get source openssh-client shows the appropriate code:

    fflag = tflag = 0;
    while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
          switch (ch) {
          ..
          ..
            case 'P':
                    addargs(&remote_remote_args, "-p");
                    addargs(&remote_remote_args, "%s", optarg);
                    addargs(&args, "-p");
                    addargs(&args, "%s", optarg);
                    break;
          ..
          ..
            case 'p':
                    pflag = 1;
                    break;
          ..
          ..
          ..

Swapping those two flags around, and updating the format string appropriately, was sufficient to do the necessary.

In other news I've done some hardware development, using both Arduino boards and the WeMos D1-mini. I'm still at the stage where I'm flashing lights, and doing similarly trivial things:

I have more complex projects planned for the future, but these are on-hold until the appropriate parts are delivered:

  • MP3 playback.
  • Bluetooth-speakers.
  • Washing machine alarm.
  • LCD clock, with time set by NTP, and relay control.

Even with a few LEDs though I've had fun, for example writing a trivial binary display.

| 4 comments

 

Comments on this entry

icon Josh Triplett at 15:51 on 8 January 2017

As an alternative that doesn't require rebuilding openssh-client, you could put the following script into your $PATH as scp, ahead of /usr/bin:

#!/usr/bin/python

import os, sys os.execv("/usr/bin/scp", [{ "-P": "-p", "-p": "-P" }.get(arg, arg) for arg in sys.argv])

icon Steve Kemp at 15:54 on 8 January 2017
https://steve.fi/

Josh that's a damn fine solution! You win the internet today!

icon Jeff Epler at 15:16 on 8 January 2017
https://emergent.unpythonic.net/

My philosophy is: if I ever have to specify a port number to ssh/scp I lose.

As long as you have a setup where the alternate port numbers are static, ~/.ssh/config is very handy for this (man ssh_config)

Forgive me if these examples don't show up right, I don't know what kind of markup your comments accept.

For example, if you just have a host 'altport' where a different port is used, put a stanza like

Host altport
Port 22528

If you have a situation where several different ports on the same address go to different computers,

Host submachine
HostName realmachine
Port 22529
HostKeyAlias submachine

If you have a situation where you have to tunnel ssh, don't use port forwarding, use nc from package netcat-traditional on 'publicmachine':

Host tunnelmachine
ProxyCommand ssh publicmachine nc %h %p

(this works to replace -L forwarding but not -R forwarding., alas)

icon Steve Kemp at 15:25 on 8 January 2017
https://steve.org.uk/

To a certain extent I agree. But there are times, too many, where I have to do ad-hoc work on machines that are owned by other people and the hosts are essentially "random" until I learn about them.

In a more ideal world we'd never have to bother about non-standard ports, and everybody would use SSH-keys rather than passwords!