SSH & Remote Administration
Stop ssh-copy-id from failing when your port is not 22
đź§© The Challenge
You’ve got a fresh server set up with a non-standard SSH port because you’re tired of seeing thousands of brute force attempts in your auth logs. Then you go to use ssh-copy-id to push your pubkey and the thing just hangs there or errors out because it assumes port 22 is open.
đź’ˇ The Fix
Most people think ssh-copy-id is just a dumb script, but you can actually pass SSH options directly to it. Just tell it the port explicitly and it stops trying to talk to the wrong end of the server.
ssh-copy-id -p 2222 user@remote-host
⚙️ Why It Works
Passing the -p flag forces the underlying ssh command used by the script to connect to your specific port instead of the default. It’s a lifesaver when you’ve locked down your firewall.
🚀 Pro-Tip: Use the -i flag to specify exactly which identity file to send if you’re managing keys for different clients on the same host.
Linux Tips & Tricks | © ngelinux.com | 8/9/2026
