First of all, I am well aware of that there are many of questions regarding this topic. I have read them, but still could figure out an appropriate answer for my situation.
I would like to scp
the entire ~/cs###/assign1
dir from local to school home dir with a shell script. My question is, is there a way in my script to wait for the password prompt, and then simulate key board event to 'type' in my password?
here is a really detailed guide of how to set up the key
I agree that you should use keys. But expect can automate the interactive aspect of the process IF you want to hardcode your password in a plain-text script file.
Something like this - http://code.google.com/p/enchanter/ ?
You don't say which platform you are using at home and at school. Assuming Linux, Cygwin or OS/X you have several options:
For option (1), you would
For the second option, ssh-agent allows you to cache your password in a local process one time per session. You set an expiration time
As many have already said that using ssh keys would be the safest and best way. If anyone else is still wondering around and searching for help, in Ubuntu help there is a fast and straight forward way to use ssh keys.
Once you set up
ssh-keygen
as explained here, you can doscp -i ~/.ssh/id_rsa /local/path/to/file remote@ip.com:/path/in/remote/server/
where
id_rsa
is the local key generated in thessh-keygen
setup.If you want to lessen typing each time, you can modify your
.bash_profile
file and putThen from your terminal do
source ~/.bash_profile
. Afterwards if you typeremote_scp
in your terminal it should run thescp
command without password.Are ssh keys not allowed? That would be a better solution.