-2

I'm trying to execute this shell with command line

host="192.168.X.XXX"
user="USERNAME"
pass="MYPASS"
sshpass -p "$pass" scp -o StrictHostKeyChecking=no /home/MYPATH/File.import "$user@$host:/"home/MYPATH/

To copy a file from my local server in to remote server. The remote server is a copy of the remote server but when I try to execute this shell I have this error:

**PERMISSION DENIED, PLEASE TRY AGAIN**

I didn't understand why if I try to execute this command in command line is working.

USERNAME@MYSERVER:~$ sshpass -p 'MYPASS' scp -o StrictHostKeyChecking=no /home/MYPATH/File.import USERNAME@192.168.X.XXX:/home/MYPATH/

Somebody have a solution??

Fabio
  • 85
  • 1
  • 2
  • 14
  • try looking at this post http://serverfault.com/questions/39733/why-do-i-get-permission-denied-publickey-when-trying-to-ssh-from-local-ubunt – Thellimist Mar 13 '15 at 16:19
  • Maybe try this? sshpass -p "${pass}" scp -o StrictHostKeyChecking=no /home/MYPATH/File.import "${user}@${host}:/home/MYPATH/" – yoshiwaan Mar 13 '15 at 16:23
  • I've tried your solution but don't change... I've a permission error again! – Fabio Mar 13 '15 at 16:30

3 Answers3

5

Please use a pipe or the -e option for the password anyway.

export SSHPASS=password
sshpass -e ssh user@remote

Your simple command with -e option:

export SSHPASS=password
sshpass -e scp -o StrictHostKeyChecking=no /home/MYPATH/File.import user@192.168.X.XXX:/home/MYPATH/

Please remove the wrong quotes from your command:

sshpass -p "$pass" scp -o StrictHostKeyChecking=no /home/MYPATH/File.import $user@$host:/home/MYPATH/

You should also be able to remove the quotes around $pass.

Please ensure that you have no special characters in your pass variable or escape them correctly (and no typos anywhere).

For simplicity use a ssh command instead of scp for testing

Use the -v or -vvv option for the scp command to check what scp is trying to do. Also check the secure log or auth.log on the remote server

Patrick
  • 902
  • 1
  • 5
  • 18
  • Patrick I've tried your solution but I have the same result. Permission denied! My password is easy and don't use special characters! I don't understand why can't copy the file with shell using the same code that I use in the command line! I've tried to copy this code in crontab but no working too. – Fabio Mar 14 '15 at 15:42
  • 2
    I was having the same issue. Once I removed the quotes around the password, it worked for me. – Daryl Van Sittert Aug 27 '15 at 08:40
0

You have to install "sshpass" command then use the below snippet

export SSHPASS=password
sshpass -e  sftp user@hostname << !
   cd sftp_path
   put filename
   bye
!
0

A gotchya that I encountered was escaping special characters in the password which wasn't necessary when entering it in interactive ssh mode.

ummdorian
  • 268
  • 3
  • 4