I often have to automatically trigger some server action from a remote machine, and I have used a password-less SSH key and a dedicated account on the server for this so far.

But it turns out that SSH can provide more security. In ~/.ssh/authorized_keys, you can specify options for every key. This not only allows you to turn off port forwarding, but also to specify a command which will replace the interactive shell, or the command passed to the SSH client.

This command can be a shell script which checks what the client wants to run and executes it if it looks OK, or it can start the rsync daemon.

So to automatically run rsync over SSH, create a password-less SSH key on the client, put the public key in ~/.ssh/authorized_keys on the server, and add the following at the start of the line. Do not include the line break, and put a space between this and the key string.

no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,
command="rsync --server --daemon --config=/etc/rsyncd.conf ."
ssh-dss keydata user@example.com

In /etc/rsyncd.conf, list the directories the client may access. Because rsync will not be run by root, chroot would not work.

use chroot = no 

[backup]
path = /var/backup
read only = yes

On the client, you then run rsync like below to fetch the latest backup files. Note the double colon between the host name and the module name. If needed, you could append a directory or file path after the module name.

rsync -e "ssh -i $HOME/.ssh/id_dsa-backup" \
-a --delete server.example.com::backup/ /data/server-backup

Of course, it's still a good idea to use a dedicated account on the server for this.

21:58, 25 May 2005 by Carsten Clasohm Permalink | Comments (0)

RSS

Archive

May 2005
S M T W T F S
10  11  12  13  14 
15  16  17  18  19  20  21 
22  23  24  25  26  27  28 
29  30  31         
September 2008
July 2008
June 2007
May 2007
March 2007
January 2007
December 2006
September 2006
June 2006
April 2006
March 2006
February 2006
January 2006
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
January 2005
December 2004
November 2004
October 2004

Blog Categories

Hiking (5)
Desktop Linux (28)
Server Linux (5)
Palm (3)
Photography (5)
Politics (2)
Web Applications (15)

Notifications

Request notifications

Syndication Feed

RSS

Recent Comments

  1. Anonymous Visitor: Security issue
  2. Anonymous Visitor: Thanks
  3. Anonymous Visitor: AT&T U.S.
  4. Anonymous Visitor: All went well under CentOS 5.0 in Croatia (VIP network)
  5. Anonymous Visitor: tmp crypt not necessary
  6. Anonymous Visitor: Great article
  7. Anonymous Visitor: So it's not a Virus...
  8. Anonymous Visitor: Thanks! Helps also on Windows!
  9. Anonymous Visitor: Thank you
  10. Anonymous Visitor: Economic Incentives