1

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.

2
  • The "-t" should not be necessary here? And you should quote "$1" and "$2". Does that change anything? If not, what happens if you run the first command twice?
    – markgraf
    Commented Sep 7, 2019 at 17:53
  • @markgraf ya i am using quote for $1 and $2 and it tried removing -t also it didn't work for me still same
    – Rahul
    Commented Sep 8, 2019 at 6:23

2 Answers 2

0

I have created a similar environment but didn't faced any such issues as you mentioned, group got changed successfully.

Did you tried executing one by one? is that working? If it is working can you try adding sleep of 5 second in-between ssh commands and try once?

0

The issue is with GID of groups, i am creating local group in each instance with same name but they have different GID because of this the last command which is executing in the functions is changing permission.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .