Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

4 Answers 4

up vote 2 down vote accepted

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

Host secret-host.example.com
Port 2222
share|improve this answer

I use this command, note the quotes:

ssh-copy-id -i ~/.ssh/id_dsa.pub "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/id_rsa.pub ‘-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.