scripting question regarding in remote login to clients

Latest response

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.

Thank you all for your input and it is much appreciated. But is ssh installed by default? i am not sure our system has this and as I cannot install the program from the internet. I might have to find other options if I cannot get the program.

The sshpass RPM is not part of the default repos. I'm off work, today, so only have my personal CentOS sysytem to look at: the sshpass RPM is in the "extras" repository - not sure which RH repository it's in.

Hi Thomas,

My Satellite 6.3 tells me it is in:

Red Hat Enterprise Linux 7 Server - Extras RPMs x86_64

Regards,

Jan Gerrit Kootstra

Hi Jon,

To answer your question from earlier, yes, generally ssh is installed by default, unless perhaps you selected a minimal bare bones installation.

Regards,

RJ

I assumed the OP meant sshpass rather than the ssh client:

  1. The openssh RPM is part of @core: you'd have to have a ridiculously-minimized build that explicitly removed that package to not have ssh.
  2. OP also stated they're using ssh-copy-id which is part of the openssh-clients package

And you're probably correct Thomas, I was just attempting to answer his question directly where he asks "But is ssh installed by default? ", even if it's for the benefit for others who land here. Your tips are always worthwhile and ought to be seriously considered.

Sorry for the confusion. That is correct I need to have the sshpass command which i believe is not i n the system. Again thanks for the help.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.