## ssh-copy-id and sshd port

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)

You can leave a trackback using this URL: http://mikegerwitz.com/ssh-copy-id-and-sshd-port/trackback/

1. [...] tip to Mike Gerwitz for getting me looking in the right direction, although the solution described on his blog does not [...]

1. ssh-copy-id -i ~/.ssh/id_rsa.pub ‘-p xxxx username@host’
also works and is more intuitive

Posted July 18, 2010 at 9:05 am | Permalink
2. 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

Posted December 7, 2010 at 4:22 pm | Permalink
3. Lionel

Totally worked, thanks.

Posted December 10, 2010 at 12:00 am | Permalink
4. Pascal

Thank you for saving my time!

Posted August 12, 2011 at 10:00 am | Permalink
5. juan

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?

(Sorry I can’t include the character tilde right now!)

Posted August 25, 2011 at 6:18 pm | Permalink
6. Mike

Thanks very much for not only a solution, but the explanation. It was just what I needed.

Posted August 27, 2011 at 8:24 pm | Permalink
7. this worked for me too, thanks – and yes, the error was confusing!

Posted September 19, 2011 at 12:18 pm | Permalink
8. 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.

Posted January 4, 2012 at 6:15 pm | Permalink
9. rene

Cool, thanks for sharing the fix!

Posted September 26, 2012 at 4:41 pm | Permalink