Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a server with SSH running on a non-standard port. Instead of 22, it runs on 8129. To log in, I use:

ssh -p 8129 hostname

Now, whenever I need to set up a key for password-less login, I have to copy the public key and add it to authorized_keys manually. I discovered that the command ssh-copy-id could be used to simplify this process, but it seems like it does not have an option to specify the port of the ssh server.

Is there some way to tell ssh-copy-id to use port 8129, or should I just forget about this command and copy/paste manually as before?

share|improve this question
add comment

6 Answers 6

up vote 35 down vote accepted

$ ssh-copy-id "user@host -p 8129"

Source: http://it-ride.blogspot.com/2009/11/use-ssh-copy-id-on-different-port.html

share|improve this answer
add comment

A quick look at the source indicates that ssh-copy-id appears to have no function that permits this. However, you could do something like the following instead:

ssh -p8129 user@host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_*.pub
share|improve this answer
add comment

ssh-copy-id doesn't take any arguments that it could pass down to the underlying ssh command, but you can configure an alias in ~/.ssh/config.

Host myhost
HostName hostname
Port 8129

Then run ssh-copy-id myhost.

share|improve this answer
    
This also has the benefit of removing the need for the -p flag on regular ssh attempts. It is therefore not only the right answer to this question, it is The Right Thing, period. –  Warren Young Jan 20 '12 at 14:00
add comment

I have always used scp to copy it over:

scp -P 8129 ~/.ssh/id_*.pub user@host:
ssh -p 8129 user@host 'cat id_*.pub >> ~/.ssh/authorized_keys'

Though I must say, I'll probably be using the other (one-line/connection) methods if I remember them in the future. But this is another option for you.

share|improve this answer
add comment

This works (from here):

ssh-copy-id -i ~/.ssh/id_rsa.pub ‘-p 221 username@host’
share|improve this answer
add comment

I don't know how this works - but it's working fine:

ssh-copy-id "user@host -p PORT"

I found it on this blog .

share|improve this answer
    
This is the same as the accepted answer that was posted 7 months before yours. You even link to the same blog post. –  Barmar Jul 2 at 23:55
add comment

Your Answer

 
discard

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.