how do i pass a password to scp prior to running it in the background? keys disabled
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how do i pass a password to scp prior to running it in the background? keys disabled
I have a script that runs a bunch of SCPs in the background. I need to somehow pass the password to SCP before it starts running in the background. The SSH keys are disabled in most environments, so that's not an option. SSH has an -f option "Requests ssh to go to background just before command execution", but I don't see anything similar for scp. Any help or insight would be appreciated.
I have a script that runs a bunch of SCPs in the background. I need to somehow pass the password to SCP before it starts running in the background. The SSH keys are disabled in most environments, so that's not an option. SSH has an -f option "Requests ssh to go to background just before command execution", but I don't see anything similar for scp. Any help or insight would be appreciated.
Thanks
Basically you'd have to write a simple expect script.
Basically you'd have to write a simple expect script.
Thanks for the info but if Expect was something already packaged with linux, it would have been an option. It wouldn't be a good idea to install something throughout our environment for one simple use. There has to be a way of achieving this.
Anyways, the scp program lacks the option but you can get the desired effect with connection multiplexing:
Code:
# setup the connection
ssh -fNM -o "ControlPath $HOME/%r@%h:%p.ssh" host
...
# transfer the file in background
scp -o "ControlPath $HOME/%r@%h:%p.ssh" file host:file &
SCP_PROC=$!
...
# close the connection after transfer ends
wait $SCP_PROC
ssh -o "ControlPath $HOME/%r@%h:%p.ssh" -O exit host
Thanks, It will work for me but I can't close the connection without killing the process and removing $HOME/%r@%h:%p.ssh. -O is not an available option.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.