使用 public 键编写 SCP

Script SCP with public key

我需要配置一个脚本来将一些文件从一个 Ubuntu 服务器复制到另一个。

我正在尝试配置此脚本:

#!/bin/sh

#Monitoring
for i in 192.168.0.10 192.168.0.11;
do
  su customuser -l -c "scp -oStrictHostKeyChecking=accept-new -oPasswordAuthentication=no -oBindAddress=0.0.0.0 -q -r /tmp/log/*log customuser@${i}:/data/logs/"
done

我收到此日志:

Executing: program /usr/bin/ssh host 192.168.0.10, user customuser, command scp -v -r -d -t /data/logs/
lost connection

我可以使用我在远程服务器上的帐户进行连接。但是当我尝试 运行 脚本时,日志是:

debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /data/customuser/.ssh/id_rsa
debug3: sign_and_send_pubkey: RSA SHA256:xxxxxxxx
debug3: sign_and_send_pubkey: signing using rsa-sha2-512 SHA256:xxxxxxx
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
Connection closed by 192.168.0.10 port 22

我在远程服务器上复制了私钥,并且在远程服务器上存在相同的用户customuser。 如何查看远程服务器?

我解决了,PAM模块有问题
在文件中 /etc/security/access.conf there isn't the user1.

我加了:

cat /etc/security/access.conf
-: ALL EXCEPT toor :LOCAL
-: ALL EXCEPT monitor_cli user1 toor :ALL

重新启动 sshd 服务:

service sshd restart

有效