Quickest Way: Using STDIN and Pipe to Copy SSH Public Key to Server

Tags: July 27, 2016 8:13 PM

Goal

Copy SSH public key to another machine without using external tools such as ssh-copy-id - Only pure shell built-in or at least standard commands.

Solution

The solution is using shell STDIN and PIPE it to ssh.

$ cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys -'
The quote for the ssh arguments is important because without it the redirection will goes to your local machine instead of remote machine. The "-" at the last of cat command on the remote indicate it reads the input from STDIN.

Reference

Share on Facebook Twitter

0 comments:

Post a Comment