Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Pushing SSH Keys

Submitted by on March 21, 2017 – 10:54 am

This is just a quick note for me on pushing SSH keys using sshpass and xargs. The ~/hosts.txt file contains a list of remote hosts, one per line. And the ~/.passwd.txt contains your password. Make sure to chmod 400 ~/.passwd.txt and delete it after you’re done, to maintain some semblance of security. Another option is to read -s SSHPASS; export SSHPASS and then use sshpass -e to work with the environment variable. I don’t know if this is more secure, but it’s more of a hassle, so it must be.

And here’s the command. Pretty simple:

xargs -n 1 -P 10 -a ~/hosts.txt -I % sshpass -f ~/.passwd.txt ssh-copy-id '-o ConnectTimeout=5 -o StrictHostKeyChecking=no %' 2>/dev/null

You can adjust the number of parallel threads -P based on the number of CPU cores you have. Also, when running many parallel threads, you may want to up the ConnectionTimeout value.

Print Friendly, PDF & Email

Leave a Reply