I'd like to copy
squid.conf from one server to another.
- The servers don't talk to each other. I'd like to go through my workstation.
- Both servers have the file, so it will be overwritten on the target.
- The files have
600permission and are owned by root.
- root login via ssh is disabled (
- I'd like to do it in one line, if possible, since it will be a part of a setup guide.
I know to do
ssh source 'tar czpf - -C /etc/squid/ squid.conf' | \
ssh target 'tar xzpf - -C /etc/squid/'
to copy files between servers and preserve permissions. However, in this case I will get "Permission denied".
I also know I can do this:
ssh -t source 'sudo cat /etc/squid/squid.conf'
This way the
-t allows sudo to ask for the admin password before outputing the content of the file.
The problem is, I don't know how to combine those techniques into something that will ask for the sudo password on each server, and transfer the file to its destination. Is this possible?
UPDATE: Here's the best I could come up with:
ssh -t source 'sudo tar czf /tmp/squid.tgz -C /etc/squid squid.conf' && \
ssh source 'cat /tmp/squid.tgz' | \
ssh target 'cat >/tmp/squid.tgz' && \
ssh -t source 'sudo rm /tmp/squid.tgz' && \
ssh -t target \
'sudo tar xzf /tmp/squid.tgz -C /etc/squid && sudo rm /tmp/squid.tgz'
Calling this a one-liner seems like a stretch. I think I'll just break it down to separate steps in the setup guide.