0

I am trying to transfer some files using SCP in a shell script, but I am being prompted for my password on the remote machine.

Can I use expect with scp to enter the password so I don't have to type it in all the time?

voretaq7
  • 79,879
  • 17
  • 130
  • 214
Mohammad AL-Rawabdeh
  • 1,612
  • 12
  • 33
  • 54

3 Answers3

5

You don't. Use a key instead.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • i know but in this task i want use expect command – Mohammad AL-Rawabdeh Dec 05 '10 at 07:02
  • 4
    Using `expect` to do this is terribly insecure -- If you want an answer about using expect you are going to have to justify why you think expect is the right tool or the job. – James Dec 05 '10 at 10:45
  • A reason could be that he can't put his pubkey on the server or it doesn't accept publickey. Actually, scp must read the secret key too, and usually the only security on it is the 700 on the .ssh directory. – ott-- Jul 27 '12 at 21:22
2

Yes, you can.

#!/usr/bin/bash
/usr/bin/expect <<EOD
spawn /usr/bin/scp -l 200 file.ext  user@server://path/on/server/
expect "password:"
send "YourPassword\r"
expect "\r"
send "\r\n"
EOD
Nick
  • 21
  • 1
  • As written, this means that the user has to create/edit a shell script every time, rather than merely writing their password, which doesn't feel like a good substitute. :) Perhaps you could improve this script by using `$@` to pass the command line parameters through to `scp`? – nickgrim Apr 26 '13 at 16:08
0

You can not bypass prompt by SCP.

What you can do to enter without passphrase is to use identity file. You can do this by setting up an Identity key. Instead of using password prompt you specify the location of identity file. If you need information about how to set this up , please use the given link : https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server

c0der512
  • 121
  • 5