I need to configure a script to copy some files from one Ubuntu server to another.
I'm trying to configure this script:
#!/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
I receive this log:
Executing: program /usr/bin/ssh host 192.168.0.10, user customuser, command scp -v -r -d -t /data/logs/
lost connection
I can connect using my account on the remote server. but when I try to run the script the log are:
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
I copied the private key on the remote servers, and on the remote server exist the same user customuser
.
How can check on the remote server?
I solved, there problem was in the PAM module.
In the file /etc/security/access.conf there isn't the user1.
I added it:
cat /etc/security/access.conf
-: ALL EXCEPT toor :LOCAL
-: ALL EXCEPT monitor_cli user1 toor :ALL
Restart the sshd
service:
service sshd restart
and it works