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 2122scp

努力する

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

大文字の使用に注意してくださいP

~によるとman scp:

-P port

    接続するリモートホストのポートを指定します。このオプションは大文字の「P」で記述されます。-pファイルの保存に使用された時間とモードはrcp(1)に保存されます。

おすすめ記事