Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way to push configuration from one central machine to several remote machines without the need to install anything on the remote machines.

The aim is to do something like you would find with tools like cfengine, but on a set of machines that don't have agents set up. This might actually be a good technique of setting up cfagent on a set of existing remote machines.

share|improve this question
Similar on SO: – AlikElzin-kilaka May 18 '15 at 12:46
The actual questions has 23 upvotes where the duplicate on SO has 55 :P – MoJo Sep 2 '15 at 12:16
up vote 39 down vote accepted

You can pass a script and have it execute ephemerally by piping it in and executing a shell.


echo "ls -l; echo 'Hello World'" | ssh me@myserver /bin/bash

Naturally, the "ls -l; echo 'Hello World'" part could be replaced with a bash script stored in a file on the local machine.


cat | ssh me@myserver /bin/bash


share|improve this answer
How do I make this run as sudo on the remote system.e.g. If I was logged on the remote server I would usually run this as sudo -u testuser – Sharjeel Mar 14 '13 at 11:53
What if the script I am calling involves user interactions??? – Abhimanyu Srivastava Mar 18 '13 at 5:14
this is like magic for me!!! thank you! – jasdeepkhalsa Feb 19 '14 at 14:21

I would recommend python's Fabric for this purpose:

# ~/

from fabric_api import *

env.hosts = ['host1', 'host2']
def deploy_script():
    put('', '', mode=0755)

# from shell
$ fab deploy_script

You should be able to use the above to get started. Consult Fabric's excellent documentation to do the rest. As an addendum, it's totally possible to write your script wholly within Fabric -- no copying needed, however it should be noted that to change the script on all machines, you would only need to edit the local copy and redeploy. Furthermore, with a little more than basic usage of the API, you can modify the script based on which host it is currently running on and/or other variables. It's a sort of pythonic Expect.

share|improve this answer
I don't think this exactly answers the question, but I like the idea and I could see Fabric as a useful tool. – tremoloqui Dec 23 '10 at 22:24
@tremoloqui Fabric is a python wrapper around ssh - nothing needs to be installed on the target machines, save the script being pushed. Which, if rewritten as a series of Fabric commands (using run and sudo), isn't even needed. – Izkata Feb 9 '12 at 15:18

There are several ways to do it.


ssh user@remote_server 'bash -s' < localfile


cat localfile  | ssh user@remote_server


ssh user@remote_server "$(< localfile)"

number 3 is my prefered way, it allows interactive commands e.g. su -S service nginx restart

(#1 will consume the rest of the script as input for the password question when you use su -S.)

share|improve this answer
Regarding running local script on remote machine -- Is there a way to send variable as an argument to the remote machine.. ? i.e along with the script, i want to send a variable (having multiple lines) as argument to the remote machine. The script then intends to use the variable. – user257194 Dec 4 '14 at 23:08
#3 is incredible dude! – the0ther Apr 4 at 19:30

This is exactly what Ansible is used for. There is no agent, you just have to create a text file called:


with content that looks something like:


This would specify that machines "web1, web2...web8" are in the group "webhosts". Then you can do things like:

ansible webhosts -m service -a "name=apache2 state=restarted" --sudo

to restart the apache2 service on all your machines, using sudo.

You can do on the fly commands like:

ansible webhosts -m shell -a "df -h"

or you can run a local script on the remote machine:

ansible webhosts -m script -a "./"

or you can create a playbook (look up the documentation for details) with a complete configuration that you want your servers to conform to and deploy it with:

ansible-playbook webplaybook.yml

Basically you can start using it as a command line tool for running commands on multiple servers and expand its usage out into a complete configuration tool as you see fit.

share|improve this answer
I like ansible as much as the next guy, but if he's asking about a script, then ansible has a really nice script module: ansible webhosts -m script – ptman Aug 15 '14 at 11:47
All the other answers involve a bash script, but it's not what he specifically asked for. He just said pushing config to remote machines. But good mention of the script module :) – seumasmac Aug 15 '14 at 16:15
Please vote up this answer! This is the way to do it! – chicks Aug 22 '15 at 17:31
@ptman I have only just noticed that while he doesn't mention a script in the question, he does in the title! Sorry. I've updated. – seumasmac Sep 22 '15 at 20:42

As explained in this answer you can use heredoc :

ssh user@host <<'ENDSSH'
#commands to run on remote host

You have to be careful with heredoc, because it just sends text, but it doesn't really wait for the response. That means it will not wait for your commands to be executed.

share|improve this answer

Why not simply copy the script first, then running it?

scp the_server:
ssh the_server "chmod +x; ./"

Of course you should be careful not to upload it to a world-writable place, so nobody else could fiddle with it before you run it (possibly as root).

share|improve this answer
The reason I don't want to upload the script is so it doesn't have to be managed and have the risks that you mentioned. Also, it seems to me that it's simpler than the multi-step process of uploading, processing and (optionally) deleting. – tremoloqui Dec 23 '10 at 20:21

Rewrite the script in a way that each command in it already is prefixed with ssh and a hostname/ip or list of such is passed to the script as an argument (assuming you have passwordless/ssh-agent key authentication set up). Some work might be necessary to correctly pass error/return codes back from the remote commands ....

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.