I need to copy some data from a cluster of very restricted machines through the network which currently has DNS problems (so some connections are bizarrely not working).
I found that the only way to copy the data from a machine is running scp from that machine.
For now the workflow is:
- for each machine in machines
ssh machine
- enter password
scp files destination:results
- enter password
- wait
- repeat forever
I'm going mad over this manual labor. I want a solution which allows me to enter the password a single time.
I've searched for solutions. Most recommend installing SSH keys, but this requires the same procedure to distribute the keys. Other mention the expect
program, but I don't have it on that system.
How can this be accomplished?
Update:
The main machine runs FreeBSD 9 and the 100 servers run Ubuntu 12.
I don't have root on any machine.
Best Answer
I will assume that these are all Linux hosts and that you have root access to them. I will also assume that they are using
apt
for package management, but it is easy to apply this solution withyum
orpacman
or any other package manager.As far as I know,
ssh
offers no way of specifying a password on the command line so first you will need to installsshpass
on your local machine:This will allow you to pass the password as a command line argument:
Now, create a file with all the IPs you are interested in, one per line. You can parse this file to install
sshpass
on each remote machine. If your password isfoo
and you are connecting asroot
, you can dosshpass
is now installed on each server. Now, go through the servers again, and copy your files. If you are copying asroot
and theroot
password for yourdestination
isbar
, do this:You can also use
sshpass
to copỳ your key files and --as long as you've used an empty passphrase-- allow passwordless access so you don't have this problem next time around:Once that is done, you will be able to copy the files over using: