I got the same error message when I tried to log in with a non-standard port.
To debug, I ran the script, prefixing bash -x
. Here's where I ran into issues:
+ ssh -p8882 'umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys'
So it took the command line option '-p8882' and tried to use that as the machine to try to reach. Needless to say it failed. I'd have to see your output to isolate your issue further though.
As teeks99 said, make certain you can log in with your password first though. This should isolate "can't log in with ssh" issues from "ssh-copy-id is broken somehow" issues.
Edited to add:
you can get around some of the issues of not being able to pass any additional arguments to ssh by creating or adding to a file called ~/.ssh/config
:
Host shortname
HostName ec2-0-0-0-0.compute-1.amazonaws.com
Port 8882
IdentityFile ~/.ssh/nonstandard.name
User ubuntu
man 5 ssh_config
for details
With roughly this setup, I got the script to work by just issuing ssh-copy-id shortname