For security purposes, I don’t run sshd on the default port (22). This gave me some problems when attempting to use the command ssh-copy-id. Ideally, you’d expect the following to work:
1 | ssh-copy-id -p XXXX -i '~/.ssh/id_rsa.pub' username@host |
However, that didn’t do anything but output an error:
Bad port 'umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys'
The solution was to enclose it in quotes as follows:
ssh-copy-id ‘-p XXXX -i ~/.ssh/id_rsa.pub username@host’
Hope that helps.
(The above error probably doesn’t make any sense. ssh-copy-id is a shell script. The command that appears in the error message is a command sent to the server via SSH. Feel free to take a look at the file: cat `locate ssh-copy-id | head -n1`)


1 Trackbacks
You can leave a trackback using this URL: http://mikegerwitz.com/ssh-copy-id-and-sshd-port/trackback/
[...] tip to Mike Gerwitz for getting me looking in the right direction, although the solution described on his blog does not [...]
9 Comments
ssh-copy-id -i ~/.ssh/id_rsa.pub ‘-p xxxx username@host’
also works and is more intuitive
Not only is this more intuitive, but this was the only thing that would work on my Debian Lenny (5.0.6) machine. Thanks for the tip, and you might want to consider updating the main post.
Cheers,
Antoine
Totally worked, thanks.
Thank you for saving my time!
ok, … I know this post is …. out of date, but …
I was thinking in people finding help now.
I think that the problem is not the port assigned to ssh, but the use of the characer tilde (this represents home isn’t it?) in the command, when someone enclose the line like “ssh xxxx ….” this “escapes” the character tilde and your command works ok.
Am I wrong?
Thanks in advance.
(Sorry I can’t include the character tilde right now!)
Thanks very much for not only a solution, but the explanation. It was just what I needed.
this worked for me too, thanks – and yes, the error was confusing!
juan – you are correct. In my case it did not matter (as the usernames were the same on both systems). I modified the post to quote the tilde in order to remove that confusion.
Cool, thanks for sharing the fix!