sshpass는 SSH와 작동하지만 SCP와 sshpass는 작동하지 않습니다.

sshpass는 SSH와 작동하지만 SCP와 sshpass는 작동하지 않습니다.

제 경우에는 sshpass를 이용해 SCP를 통해 파일을 보내려고 했으나 실패하는 상황이 발생했습니다. 비밀번호가 포함된 스크립트를 사용해야 하는데 가장 간단한 방법이 작동하지 않습니다.

HostName2에서는 sshd_config 등의 구성을 볼 수 없고 ssh-copy-id를 보낼 수 없습니다. "myPass"를 사용해야 합니다.

이거 봐요:

sshpass -p 'myPass' ssh -p 2122 [email protected]      

^ 알았어

sshpass -p 'myPass' scp ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB

^아니요

잘 작동합니다:

[tomcat@hostName .ssh]$ sshpass -p 'myPass' ssh -p 2122 [email protected]
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

아직도 질문이 있습니다:

[tomcat@hostName .ssh]$ sshpass -p 'myPass' scp -vvv ~/myDir/testPB.txt [email protected]:/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

뭐가 문제 야?

답변1

대체 포트를 사용할 수 ssh -p 2122있지만 scp.

노력하다

sshpass -p 'myPass' scp -P 2122 ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB

대문자 사용에 주의하세요 P.

~에 따르면man scp:

-P port

    연결할 원격 호스트의 포트를 지정합니다. 이 옵션은 대문자 "P"로 작성됩니다.-p파일을 저장하는 데 사용된 시간과 모드는 rcp(1)에 보존됩니다.

관련 정보