Running Rsync and Sudo over SSH

April 7th, 2011 Category: Linux Server

I often use rsync for doing backups. But if you want to do a remote backup and want to backup files and directories which are owned by different users or the root user running using rsync is difficult if you have disabled root login in your sshd_config using the statement PermitRootLogin no. For sure this is the recommended setting if your server to backup has a public IP address.

A nice and easy solution which works best for me is to use sudo. This will allow to run rsync via ssh and sudo. To get it running you have to add an entry into your sudoers config file:

/etc/sudoers

backup_user ALL=(root)NOPASSWD:/usr/bin/rsync

This will allow the user backup_user to run the command rsync as root.

Next step is to add an rsync-path parameter to the remote rsync call:

rsync --rsync-path="sudo rsync" backup_user@myhosttobackup.net:/root /backup_directory

Finally rsync will automatically do an sudo to root on the remote server and all to backup all files owned by root as well.

Links:

Share and Enjoy:
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Webnews
  • MisterWong
  • Y!GG
  • Facebook
  • Furl
  • Google Bookmarks
  • Live-MSN
  • Readster
  • YahooMyWeb

Related posts:

  1. socket: Address family not supported by protocol
  2. Simple MySql Backup Script
  3. PuTTY SSH Login Without Password Prompt
  4. Continous SSH Attacks
  5. Defending Againt SSH Attacks
This entry was posted on Thursday, April 7th, 2011 and is filed under Linux Server. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply