This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Sunday, March 18, 2018

How to Add SSH Public Key to Remote Server(s) in a Single Command.

Below command is used to copy the key to single server.

# cat id_rsa.pub | ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'

Below command is used to copy the key to multiple server. We can use for loop.

# for i in  `cat serverlist`; do echo $i; cat id_rsa.pub |
ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'; done

Hope it helps.

No comments:

Post a Comment