Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make ssh-copy-id use a port other than 22?

I tried it with -p but I get:

ssh-copy-id -p XXX XXXX@XX.XX.XX.XX
Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

I know that the port is good because I'm connected to the server on that port.

share|improve this question
up vote 3 down vote accepted

Set the port to use in ~/.ssh/config like the following:

Port 2222
share|improve this answer

I use this command, note the quotes:

ssh-copy-id -i ~/.ssh/ "user@host -p 6842"
share|improve this answer

Try this:

ssh-copy-id "user@host -p 8888"
share|improve this answer
ssh-copy-id -i ~/.ssh/ ‘-p 221 username@host’

From: Is it possible to run ssh-copy-id on port other than 22?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.