Article 4VE81 Using ssh and rsync to mirror a directory on a remote network (permission denied error)

Using ssh and rsync to mirror a directory on a remote network (permission denied error)

by
acacius
from LinuxQuestions.org on (#4VE81)
I am doing this as a project for work, so I am only able to test it in my local network, but it doesn't even work in my local network. All hosts are running CentOS 7. This is what I'm trying to do:

I have a remote network of 4 hosts: I want to run a command from my local host to one of the remote hosts which will copy a directory of files to the other 3 hosts, mirroring its own directory (using rsync). I am hoping ssh and rsync are the proper tools for this job, and not something like ncat for example.

Now, to test it at my local network, I am using only 2 computers intead of 4. This is my script: (fyi the reason it asks for the user to manually input IPs is that they change from network to network of different clients, it's not just for one remote network.)

Code:#!/bin/bash

declare -a ARRAY

read -p "enter remote IP address: "

REMOTE_ADDRESS="$REPLY" #remote address is stored in a variable

# this loop is for capturing the other three addresses local to that
# REMOTE_ADDRESS computer, putting them in an array.
# then input q when done entering.

while ! [ "$REPLY" = "q" ]; do
read -p "enter local IP address: "

case "$REPLY" in
"q") break
esac

ARRAY+=("$REPLY")
done

# this loop is for using ssh to connect to the remote computer and run a
# command that starts 3 ssh processes on it, each forking to the background
# and copying its local files to the other 3 computers. rsync is silent, the -v
# option is not used here.
# I want this to mirror that particular directory on all 4 computers.

for i in ${ARRAY[@]}; do
ssh -f $REMOTE_ADDRESS "rsync -a '/home/demo/test_dir' $i:/home/demo/main/practice/"
doneThe problem is, when I try to use it (on my own computer, 192.168.0.94), it says this:

Code:$ ./script.sh
enter remote IP address: 192.168.0.107
enter local IP address: 192.168.0.94
enter local IP address: q
$ Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]

$I checked the permissions on the authorized_keys file is 0600 on all systems, and the ~/.ssh folder has permissions of 0700.

I looked at debug output of ssh -vvv but the only thing that caught my eye was,

Code:debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1000)In the /etc/ssh/sshd_config file on both systems, this is set:

Code:PubkeyAuthentication yesI have set up a one-way passwordless login from my own system to the .107 system. I am not sure why it says permission denied when I try ssh with the rsync command.latest?d=yIl2AUoC8zA latest?i=xZmhaO7kwKY:sBbOKsXBnDU:F7zBnMy latest?i=xZmhaO7kwKY:sBbOKsXBnDU:V_sGLiP latest?d=qj6IDK7rITs latest?i=xZmhaO7kwKY:sBbOKsXBnDU:gIN9vFwxZmhaO7kwKY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments