Quickly create and transfer openssh keys to multiple servers

First step is to create an openssh key.

On Linux:

ssh-keygen -t rsa


#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/serverlogin
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/serverlogin.
Your public key has been saved in /root/.ssh/serverlogin.pub.
The key fingerprint is:
7a:ce:aa:43:er:7c:bb:10:4b:88:84:63:ac:fa:61:74 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
| .               |
|o..              |
|.o.. .           |
| .o A o R        |
| ... . +         |
| .o0.  + .       |
|...oo0 .*        |
|...o++oo+        |

Next you might need to transfer this openssh key to Windows. You can use pscp:

pscp [email protected]:/root/.ssh/serverlogin D:\Software\MyKeys\

Now from the server, transfer the public key to multiple servers:

cat ~/.ssh/serverlogin.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
cat ~/.ssh/serverlogin.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.