Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 trying to write a script that pushes a website to my server, where the website files are on my local machine for testing.

It works now, by using rsync to update the server, then ssh to get the server to run a script that does a few things (namely restart apache – the website uses WSGI).

The problem is that I have to input my password for the server twice, which I am not fond of.

Is there a way to make it so that I only have to input my password once? I don't particularly want to not have to enter my password at all, so I would like to have some way to do it without the ssh-key thing.

share|improve this question
> have some way to do it without the ssh-key thing – this is exactly what these keys are for. Any specific reason why you don't want to do this? – slhck Sep 19 '11 at 12:38
I mean – and this is kind of a cheap solution – you could probably do it with SSH keys and just make the script run with root privileges only. – slhck Sep 19 '11 at 12:52

Look up the -M and -S options in ssh(1). The idea is to open a master connection to the server, and then do multiple accesses as slave connections through the open socket. Also see ControlMaster and ControlPath in the ssh_config(5) manual.

share|improve this answer

We have a similar complicated setup at our university. Users are required to use password login.

Eventually I learnt about expect which can automate this.

In my case I made my program a bit unreadable so that the password would not be obvious visible.

Anyway – first well readable example I found is here:

spawn  sftp  -b cmdFile
expect "password:"
send "shhh!\n"; 

The idea is to completely recreate the process of your manual logon. So you will need to know beforehand what "questions" your script will encounter and what it should reply.

Also the command in my case it was

spawn  ssh

Replace the string in expect to what is shown in YOUR case – and also input replies as will be required there.

So e.g. if you have to enter your password twice – add another

expect "password:"
send "my_super_secret_password\n"; 

Don't forget to add the commands for putting your website in the script ;) It will look like:

expect "prompt:"
send "update my website\n"
share|improve this answer

There is a similar questions with another descriptive answer you can find HERE.

Just in case it is helpful, I made this generic script with two different rsync processes following Kusalananda's suggestion:

#!/usr/bin/env bash


mkdir -P ~/.ssh/ctl
ssh -nNf -o ControlMaster=yes -o ControlPath="$HOME/.ssh/ctl/%L-%r@%h:%p" $REMOTEUSER@$REMOTEHOST

rsync -axuv -e "ssh -o 'ControlPath=$HOME/.ssh/ctl/%L-%r@%h:%p'" --progress --delete-after /localdir01/ $REMOTEUSER@$REMOTEHOST:/remotedir01/

rsync -axuv -e "ssh -o 'ControlPath=$HOME/.ssh/ctl/%L-%r@%h:%p'" --progress --delete-after /localdir02/ $REMOTEUSER@$REMOTEHOST:/remotedir02/

ssh -O exit -o ControlPath="$HOME/.ssh/ctl/%L-%r@%h:%p" $REMOTEUSER@$REMOTEHOST
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.