I am trying to set group permission on directories in remote instances using a function which will take input of directory and group and the function is as below total there are three instances of which Instances A & B share same common key. But the ssh command of A_IP is not changing the permission on the directory in A_IP remote instance where as on B_IP its working fine i tried interchanging the sequence of command execution by keep B_IP as first line in function in that case B_IP ssh command is not changing the permission where as A_IP ssh command is changing the permissions on the directory. What i observer the one of the A_IP or B_IP which are sharing the common key file to login the one which is placed first in the sequence of command is unable to run the ssh command to change permission on remote system
grouppermission () {
dir=$1
group=$2
ssh -i $A_Key -p 2022 ec2-user@$A_IP -t "sudo chown -R :$group $dir"
ssh -i $A_Key -p 2022 ec2-user@$B_IP -t "sudo chown -R :$group $dir"
ssh -i $B_Key -p 2022 ec2-user@$C_IP -t "sudo chown -R :$group $dir"
}
Please helping in solving the issue. I am using centos operating system.