就我而言,我有一种情况,我试图使用 sshpass 通过 SCP 发送文件,但我不能。我需要使用带密码的脚本,但最简单的方法不起作用
在 hostName2 上,我无法看到配置 sshd_config 等并发送 ssh-copy-id,我需要使用“myPass”
看这个:
sshpass -p 'myPass' ssh -p 2122 tomcat@xxx.xxx.xx.xxx
Run Code Online (Sandbox Code Playgroud)
^ 好的
sshpass -p 'myPass' scp ~/myDir/testPB.txt tomcat@xxx.xxx.xx.xxx:/chroot/tomcat/testPB
Run Code Online (Sandbox Code Playgroud)
^不正常
它工作正常:
[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
Run Code Online (Sandbox Code Playgroud)
并且有一个问题:
[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
Run Code Online (Sandbox Code Playgroud)
怎么了?
Arc*_*mar 26
您使用替代端口,ssh -p 2122
但不使用scp
。
尝试
sshpass -p 'myPass' scp -P 2122 ~/myDir/testPB.txt tomcat@xxx.xxx.xx.xxx:/chroot/tomcat/testPB
Run Code Online (Sandbox Code Playgroud)
请注意大写P。
根据man scp
:
-P port
指定要连接到远程主机上的端口。请注意,此选项用大写的“P”编写,因为
-p
它已经保留用于在 rcp(1) 中保留文件的时间和模式。
归档时间: |
|
查看次数: |
46649 次 |
最近记录: |