5

In my case I have situation that I'm trying to send file via scp using sshpass but I can't. I need to use script with password but the easiest way doesn't work

on the hostName2 i have no possibility to see configuration sshd_config etc. and send ssh-copy-id, I need use 'myPass'

look at this:

sshpass -p 'myPass' ssh -p 2122 tomcat@xxx.xxx.xx.xxx      

^ OK

sshpass -p 'myPass' scp ~/myDir/testPB.txt tomcat@xxx.xxx.xx.xxx:/chroot/tomcat/testPB

^NOT OK

It works fine :

[tomcat@hostName .ssh]$ sshpass -p 'myPass' ssh -p 2122 tomcat@xxx.xxx.xx.xxx
Last login: Mon Aug 22 11:41:32 2016 from xxx.xxx.xx.xxx
#################
# hostName2 #
#################

JAVA_HOME=/opt/java
TOMCAT_HOME = /chroot/tomcat
LOG = /log/tomcat , /log/apache
LOG_ARCH = /log/arch/tomcat , /log/arch/apache
STATS = /log/stats

and there is a problem:

[tomcat@hostName .ssh]$ sshpass -p 'myPass' scp -vvv ~/myDir/testPB.txt tomcat@xxx.xxx.xx.xxx:/chroot/tomcat/testPB
Executing: program /usr/bin/ssh host 195.182.52.175, user tomcat, command scp -v -t /chroot/tomcat/testPB
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to xxx.xxx.xx.xxx [xxx.xxx.xx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/tomcat/.ssh/identity type -1
debug1: identity file /home/tomcat/.ssh/identity-cert type -1
debug3: Not a RSA1 key file /home/tomcat/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/tomcat/.ssh/id_rsa type 1
debug1: identity file /home/tomcat/.ssh/id_rsa-cert type -1
debug1: identity file /home/tomcat/.ssh/id_dsa type -1
debug1: identity file /home/tomcat/.ssh/id_dsa-cert type -1
debug1: identity file /home/tomcat/.ssh/id_ecdsa type -1
debug1: identity file /home/tomcat/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host
lost connection

what's wrong ?

closed as off-topic by Stephen Harris, Jakuje, Jeff Schaller, Anthon, MelBurslan Aug 22 '16 at 18:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Stephen Harris, Jakuje, Jeff Schaller, Anthon, MelBurslan
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Does the remote file exists? sshpass -p 'myPass' ssh tomcat@xxx.xxx.xx.xxx ls /chroot/tomcat/testPB – Jakuje Aug 22 '16 at 11:04
  • exists ;) the reason was different ! thanks for Your interest. solved – MrGarfield Aug 22 '16 at 12:04
  • I vote against closing, problem is reproductible, (missing alternate port option in scp). – Archemar Aug 22 '16 at 12:08
  • I cast a VTC under the "...or went away when a typo was fixed" umbrella. Good eyes spotting the difference in ports between the two commands! – Jeff Schaller Aug 22 '16 at 13:22
17

you use an alternative port with ssh -p 2122 but not with scp.

try

sshpass -p 'myPass' scp -P 2122 ~/myDir/testPB.txt tomcat@xxx.xxx.xx.xxx:/chroot/tomcat/testPB

please note upper case P

as per man scp

-P port Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’, because -p is already reserved for preserving the times and modes of the file in rcp(1).

  • It works! Great! i appreciate that, thanks for help – MrGarfield Aug 22 '16 at 11:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.