Linux – User without home access remote machine ssh

linuxrsyncsshssh-keys

I want a production server to push backup files to a backup machine. Backups are being done via www-data cron script (as they can be edited by website cms), and once it has finished the idea is to send this files to backup server via rsync & ssh. www-data is a 'no login user' account (no home, no ~/.ssh folder).

In a 'user can login' account I would login, generate a certificate with ssh-keygen and place public key into .ssh/authorized_keys in backup machine.

How can I make this 'user no login' account to send files to remote machine with rsync and ssh?

Best Answer

How can I make this 'user no login' account to send files to remote machine with rsync and ssh?

you can try something like the following

# su -l www-data -s '/bin/bash' -c 'rsync -rzav --rsh="ssh -p 22 -i user_can_login_private.key -o StrictHostKeyChecking=no" /var/www/html/ user_can_login@{backup_machine_ip}:/backup/html/'