I'm working with two ubuntu instances on AWS (which I use a pem key to access them).
I set up rsync for both instances, and it works if I use the default user which is ubuntu@ipaddress. However if I try to use rsync with another user (I'm typing
sudo su - jenkins for example or even typing
sudo before the rsync command), then I get the following error.
Permission denied (publickey). rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: unexplained error (code 255) at io.c(226) [Receiver=3.1.0]
Steps that I've taken:
I've tried creating an ssh key (using ssh-keygen) while logged in as
jenkins and added that to the
authorized_keys file in both
/home/ubuntu/.ssh/authorized_keys (where i'm running the rsync from) and even
$JENKINS_HOME/.ssh/authorized_keys (where I tried running rsync from there too).
I even tried using the pem key to do the same thing and that didn't work either.
Here's what I'm trying to run
rsync -avuh --delete -e ssh jenkins@ipaddress:/var/lib/jenkins/* /var/lib/jenkins
And here's with the key file
rsync -avuh --delete -e 'ssh -i path/to/key.pem' firstname.lastname@example.org:/var/lib/jenkins/* /var/lib/jenkins
P.S.: The only reason why I don't want to run it with the ubuntu user is because I get
failed: Permission denied (13) on a lot of things (since the files are owned by jenkins).
I'm trying to keep the backup jenkins instance backed up constantly with the primary instance by doing a cronjob:
*/30 * * * * /usr/bin/rsync -avuh --delete -e ssh root@jenkinsprimary:/var/lib/jenkins/* /var/lib/jenkins