scripting question regarding in remote login to clients
I currently am working on a intranet which has no internet access. I would like to have the the ability to remote login to each client and generate private keys to that I can run scripts for maintenance. I have found a script that does that. See below:
ssh key-gen && for host in $(cat hosts.txt); do ssh-copy-id $host;done.
However when this is run i would need to enter the repose to the generating of the keys, and the password to the client. Is this a simple way of doing that? I have 69 clients and this would get repetitive. I did try a number of ways to does this I.E passd but due to lack of internet i cannot down load this, I also tried to enter in the password via the read command and pass the variable but could not get that do work.
Any help would be appreciated as I am new to scripting. I am writing all scripts in the bash shell.
Regards,
Jon.
Responses
This actually sounds like it might be a perfect use-case for sshpass - at least for avoiding the having to authenticate to each and every end-point you're pushing keys to. To take your current script:
ssh key-gen && for host in $(cat hosts.txt); do ssh-copy-id $host;done.
And change to (something like):
export SSHPASS=<PASSWORD_STRING>
ssh key-gen && for host in $(cat hosts.txt)
do
sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $host
done
While you take Thomas Jones' suggestion in hand, concurrently look to install Ansible (no need to pay for Ansible Tower, just flat free Ansible), and then you can use that to help you remotely perform actions against one, some or all of your systems. docs.ansible.com - it's worth looking at.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
