Ubuntu Terminal: How to ssh-copy-id When the SSH Port is not 21

For the most part, the default port for SSH access into a Linux machine is 22. However, many people change this default in the name of security, meaning that for most of our function usage, we simply need to use the -p port number switch when trying to access with that remote machine.

However, interestingly enough, the -p switch was never bundled with the useful ssh-copy-id function, meaning that should you try something like this:

ssh-copy-id -p221 -i ~/.ssh/id_rsa.pub username@host

you will get a reply back reading: Bad port ‘umask 077; test -d .ssh || mkdir .ssh ‘ cat >> .ssh/authorized_keys’.

Not exactly encouraging.

However, there is actually a simply way to fix this and use ssh-copy-id when interacting with a non-default port 22 machine. Simply enclose your port declaration together with the host name within quotation marks!

So the correct usage would now look like this:

ssh-copy-id -i ~/.ssh/id_rsa.pub ‘-p 221 username@host’

And damn it, it actually works! Nice.

Related Posts:

About Craig Lotter

South African software development manager and senior application developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • Valid

    exactly what I was looking for.
    thanks for sharing!

  • E5z8652

    s/port 21/port22/g

    (port 21 is FTP)

  • Bård

    Helped me too. Thanks!

  • Eizt

    Thanks!

    Eizt by redeyesofangel.tistory.com

  • anthonvanderneut

    Port 21 is for FTP, ssh by default takes 22

    • http://www.craiglotter.co.za/ Craig Lotter

      Oops, typo. Rectified! :)