Server Fault is a question and answer site for system and network administrators. 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 get a list of files from secure server to compare them (using diff) to the ones i modified on local version (unfortunately the company i work in is not using subversion nor git yet)

i get list of files easily with:

find . -mtime -20 | grep "\.php\|\.js\|\.css" > changedfiles.log

what i need is a script which would loop over this list and secure copy each of them (scp or rsync) to a local directory, preserving relative path name. i tried:

for line in `cat changedfiles.log`
 DIRPATH=`dirname "$line"`
 `mkdir -p myfiles/$DIRPATH`
 scp user@host:/remotepath/$line myfiles/$line

but scp keeps asking me for the password (i dont want to setup key-based authentication to scp without password)

i am not allowed to ssh on remote server so i cannot just zip the list and download them in one command

is it possible to do something to input password only once?

share|improve this question
up vote 3 down vote accepted

Rather than set up a passphraseless key, create a passphrase-protected key and use ssh-agent to ensure you only need to enter it once per job.

After generating your keys, prefix your script with something like this:

# Start a new agent
eval `ssh-agent -s`

# add keys with a two-hour time limit
ssh-add -t 7200 ~/.ssh/id_rsa

At this point, you'll be prompted for your passphrase. After your script is finished, you can have ssh-agent be killed automatically if you do not wish to let it continue to run:

# kill the agent
ssh-agent -k
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.