0

I currently use a bash script in the following format to update local data with remote one:

usr=$1
scp -P 4444 -r $usr@some.other.machine.at:/some/folder/*Tools /home/localUser/someFolder/
scp -P 4444 -r $usr@some.other.machine.at:/some/folder/*.project /home/localUser/someFolder/

i.e., I want to copy each folder (its content and subfolders) that ends with Tools and to copy each file that ends with .project from /some/folder/ (okay, I would not need -r here) at the remote machine into my local folder /home/localUser/someFolder/.

(Not sure if this is important, I run this script with bash myScript.sh)

Currently, I have to enter the remote user's password two times, once per scp command. Is there a way so that the password has to be entered only one time?

  • 2
    Why are you using passwords in the first place, if you want to script it? Set up passwordless SSH: http://askubuntu.com/q/46930/158442 – muru Feb 22 '16 at 09:12
  • @muru: I will just look into this, yet I would be still interested if there is some way to overcome the multiple password entering if passwordless SSH is not set up. – Markus Weninger Feb 22 '16 at 09:19
  • Unlike sudo, etc. SSH doesn't do credential caching. You could use sshpass to automate entering the password, but I don't see the point of doing that over setting up keys. – muru Feb 22 '16 at 09:23
  • I followed your guide in the first comment, now it works without password. I always thought that ssh would have to be configured in some special way on the server to enable this (I don't have priviliges to change something on the server), but I have to admit that I never looked into setting up ssh in detail. Also thanks for the info with sshpass, I will probably look into it additionally just for learning :) – Markus Weninger Feb 22 '16 at 09:25
  • 2
    No, default ssh server configurations always allow key-based login. On the other hand, the SSH server can be configured to only allow key-based login, and not allow password-based login at all. – muru Feb 22 '16 at 09:28
  • The question makes a lot of sense however, if passwordless ssh is set up, but the rsa file is encrypted with a password locally. Then again, for each command, a password needs to be entered. – phil294 Aug 24 '19 at 13:47

0 Answers0