2
I made a script like this one:
sync.sh
#!/bin/bash
#1st backup the file
scp user-1@ip-1:/directory/file1 /backup/location/
#2nd sync/overwrite my file to that server
scp /local/file2 user-1@ip-1:/directory/file1
#3rd restart service associated with that file
ssh -t user-1@IP-1 << EOF
sudo systemctl restart some.service
EOF
the script permission and privileges is as following:
-rwxr-x--x. 1 user-1 group-1 ~/sync.sh
I have ssh-keys configured between user-1@local
to user-1@IP-1
, I have configured visudo to restart the service and everything works great if I run the script using user-1
.
I want any other_user
in group-1
be able to run this script, but the ssh-key doesn't work in this way, it tries to generate another key. What am I missing to do this?
Or should I use a different approach? I've seen that I could use rsync for moving files around but what about restarting the service?
thank you all.
yes I agree, that's why it's only within the users of the same group. anyway my only option then it's to create a single user to be shared between the group. (not the best solution to be honest). if I modify the script so each username is fetched I would also need to modify the other servers and add them in the sudoers list every time a new user in this group is included and seems like a lot of work for a simple small script. – kgtr – 2018-09-17T15:48:33.357
@kgtr Aahh. Okay. Updated my answer with some more info :) – svin83 – 2018-09-24T13:12:04.807