0

I am trying to make a script that will sync with another folder over a ssh connection. What I want to do is sync my local folder with the folder over ssh and then perform an ssh login. For these two commands I need to enter the same password and it's a little annoying so I am trying to make a script for it to put my password into a temporary variable and pass that variable to the two spots it is requested. This is what I have.

read -s -p "Enter Password: " mypassword && echo "$mypassword" 
| rsync -vz -r `~/Desktop/Market_Maker/Market_Maker [email protected]:~/281_Projects 
&& echo | "$mypassword" ssh [email protected]`

What this ends up doing is gives me 3 password prompts and does not work at all. What is wrong with the script?

3
  • 3
    The easier option would be to use ssh keys and leave out the password thing. You cannot use echo to pass passwords into a prompt. Commented Mar 22, 2014 at 20:09
  • My school computer prevent ssh keys for security reasons (from what i'm told) Commented Mar 22, 2014 at 20:10
  • What you are attempting is a hundred times more insecure and quite likely in violation of your school's security policy as well. Commented Mar 23, 2014 at 18:43

1 Answer 1

2

Consider using sshpass to store your password for a specific login. Once installed you can run the command:

sshpass -p 'PASSWORD' ssh [email protected]

to login to the server. I think that might be the functionality you are looking for. You might also consider setting the RSYNC_PASSWORD variable to be the password in the script.

If you want to avoid storing your password in the script you can prompt for it using:

read -s RSYNC_PASSWORD

This will store the password for the duration of the scripts execution.

Sign up to request clarification or add additional context in comments.

1 Comment

Well then I would have to store my password in the script, which I would prefer to avoid if I could

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.