Deploy SSH key to remote server using ssh-copy-id

This is how to quickly deploy a SSH public key to a remote linux server. Afterwards automation tools like ansible, chef or puppet should be used.

AWS is a good opportunity to easily setup your infrastructure. A SSH key can be managed using the AWS Key-Management.
But other (less expensive) cloud provider send out initial SSH passwords. Here is how to avoid too many manual steps.

Using commands

ssh-copy-id root@remote-host

This will grab the first public key (*.pub) found in the ~/.ssh directory and transfer it to the remote host.


cat ~/.ssh/ | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Public key copied"'


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.