Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash scp several files password issue

I am trying to copy several files from a remote server into local drive in Bash using scp. Here's the part of the code

scp -r -q $USR@$IP:/home/file1.txt $PWD
scp -r -q $USR@$IP:/home/file2.txt $PWD
scp -r -q $USR@$IP:/root/file3.txt $PWD

However, the problem is that EVERY time that it wants to copy a file, it keeps asking for the password of the server, which is the same. I want it to ask only once and then copy all my files.

And please, do not suggest rsync nor making a key authentication file since I do not want to do that. Are there any other ways...? Any help would be appreciated

like image 228
Matt Avatar asked Feb 26 '26 09:02

Matt


1 Answers

You can use expect script or sshpass

sshpass -p 'password' scp ...

#!/usr/bin/expect -f
spawn scp ...
expect "password:"
send "ur_password"

An disadvantage is that your password is now in plaintext

like image 98
w00d Avatar answered Feb 28 '26 00:02

w00d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!