Hacker News new | ask | show | jobs
by acer4666 855 days ago
"The -p <port> option can be used to specify the port number to connect to when using the ssh command on Linux. The -P <port> (note: capital P) option can be used with SFTP and scp."

The most annoying thing about SSH/scp!

6 comments

What's even more annoying is that -P for scp has to be put before the target while -p for the ssh client I am using can be put after the target.

So when you write your scp command and then realize you forgot to put in the port you have to go back and put it before the target.

The most annoying thing about SCP is args ordering, I would have preferred a single direction arg for transfer details, if it meant we didn't have to worry about positional args.

Then again, I'm speaking as someone that came into the scene well after development, so that could just be annoyance via naivete.

Use ~/.ssh/config to add per host or wildcard values for port :)
~/.ssh/config is one of the simplest, most useful features I use on a daily basis. It would be easy to accomplish much of it's behavior even if it didn't exist (bash script for each account@host), but it wouldn't be as elegant.

The config-aware shell completion is especially cool.

My most recent pet hate is inability to instruct scp to ignore symlinks -.-
Huh. You're right, and it's a WONTFIX: https://bugzilla.mindrot.org/show_bug.cgi?id=485.

I hadn't even noticed, because I tend to automatically reach for rsync instead, even for single files.

Interestingly enough that ticket is about preserving and/or following - I would be happy with ignoring so it doesn’t end up in an infinite loop - as it stands a self referencing symlink with files in the same directory will result in either your disk filling up, your inodes filling up, or a maximum bested paths error (assuming your FS has such a thing).

Edit: and until the ticket you just linked, I assumed scp and cp were intended to be close equivalents, given the whole ending in ‘cp’ thing.

This right here is the next big trick behind using CTRL+R to find the last ssh command.
Great if you only ever ssh from your primary box/profiles, an amplifier of the problem (due to entering the commands less often) otherwise!
I use this for aliasing as much as for Port assignment.
This tripped me up hardcore at work recently, because I was trying to SSH into a VM using a non-standard port, but the port-forwarding went from the non-standard port into the usual 22 on the VM. So when I got "Connection Refused" on port 22, I thought that meant the connection was getting through the NAT layer but then failing at the VM for some reason.

NOPE I'd just specified the option wrong!

I always just use -o port=<xx> for this reason.
I use rsync with -e 'ssh -p PORT', so that I can also have the ability to resume just in case :D, interesting how everyone has a different solution ^^, let's see how many ways of doing the same thing can we collect in this thread
Another one is places where you can use `user@host` and those where you can't and have to use `-l user` (and thus have to use `-e 'ssh -l user'` or equivalent)

Usually I use per host `ssh_config(5)` (both for port and user) but some tools also don't make use of that!

Wait, lower case 'o' works?
Looks like I've got BSD SSH installed. From `man ssh`:

     -o option
             Can be used to give options in the format used in the configura‐
             tion file.  This is useful for specifying options for which there
             is no separate command-line flag.  For full details of the op‐
             tions listed below, and their possible values, see ssh_config(5).
`Port` is on the list underneath. So I think the idea is you run

    ssh -o <option_name> <option_value>
where the first can be `--port`. This looks like it will be really handy for me for the exact reason GP said.
Even more fun when you are doing ssh, scp and throw in some random nmap in there as well, where -P and -p are both used.
Add the lowercase -r for recursive scp and you have two screens with man pages open.
Agreed :). I always have to google which case applies where as I use ssh and scp heavily.