24892900de0434574532cc6f72b4fdba73e39176
[rsync.git] / support / rrsync.1.md
1 ## NAME
2
3 rrsync - a script to setup restricted rsync users via ssh logins
4
5 ## SYNOPSIS
6
7 ```
8 rrsync [-ro|-rw] [-munge] [-no-del] [-no-lock] [-no-overwrite]  DIR
9 ```
10
11 The single non-option argument specifies the restricted _DIR_ to use. It can be
12 relative to the user's home directory or an absolute path.
13
14 The online version of this manpage (that includes cross-linking of topics)
15 is available at <https://download.samba.org/pub/rsync/rrsync.1>.
16
17 ## DESCRIPTION
18
19 A user's ssh login can be restricted to only allow the running of an rsync
20 transfer in one of two easy ways:
21
22 * forcing the running of the rrsync script
23 * forcing the running of an rsync daemon-over-ssh command.
24
25 Both of these setups use a feature of ssh that allows a command to be forced to
26 run instead of an interactive shell.  However, if the user's home shell is bash,
27 please see [BASH SECURITY ISSUE](#) for a potential issue.
28
29 To use the rrsync script, edit the user's `~/.ssh/authorized_keys` file and add
30 a prefix like one of the following (followed by a space) in front of each
31 ssh-key line that should be restricted:
32
33 > ```
34 > command="rrsync DIR"
35 > command="rrsync -ro DIR"
36 > command="rrsync -munge -no-del DIR"
37 > ```
38
39 Then, ensure that the rrsync script has your desired option restrictions. You
40 may want to copy the script to a local bin dir with a unique name if you want
41 to have multiple configurations. One or more rrsync options can be specified
42 prior to the _DIR_ if you want to further restrict the transfer.
43
44 To use an rsync daemon setup, edit the user's `~/.ssh/authorized_keys` file and
45 add a prefix like one of the following (followed by a space) in front of each
46 ssh-key line that should be restricted:
47
48 > ```
49 > command="rsync --server --daemon ."
50 > command="rsync --server --daemon --config=/PATH/TO/rsyncd.conf ."
51 > ```
52
53 Then, ensure that the rsyncd.conf file is created with one or more module names
54 with the appropriate path and option restrictions.  If rsync's
55 [`--config`](rsync.1#dopt) option is omitted, it defaults to `~/rsyncd.conf`.
56 See the [**rsyncd.conf**(5)](rsyncd.conf.5) manpage for details of how to
57 configure an rsync daemon.
58
59 When using rrsync, there can be just one restricted dir per authorized key.  A
60 daemon setup, on the other hand, allows multiple module names inside the config
61 file, each one with its own path setting.
62
63 The remainder of this manpage is dedicated to using the rrsync script.
64
65 ## OPTIONS
66
67 0.  `-ro`
68
69     Allow only reading from the DIR. Implies [`-no-del`](#opt) and
70     [`-no-lock`](#opt).
71
72 0.  `-wo`
73
74     Allow only writing to the DIR.
75
76 0.  `-munge`
77
78     Enable rsync's [`--munge-links`](rsync.1#opt) on the server side.
79
80 0.  `-no-del`
81
82     Disable rsync's `--delete*` and `--remove*` options.
83
84 0.  `-no-lock`
85
86     Avoid the single-run (per-user) lock check.  Useful with [`-munge`](#opt).
87
88 0.  `-no-overwrite`
89
90     Enforce `--ignore-existing` on the server. Prevents overwriting existing
91     files when the server is the receiver.
92
93 0.  `-help`, `-h`
94
95     Output this help message and exit.
96
97 ## SECURITY RESTRICTIONS
98
99 The rrsync script validates the path arguments it is sent to try to restrict
100 them to staying within the specified DIR.
101
102 The rrsync script rejects rsync's [`--copy-links`](rsync.1#opt) option (by
103 default) so that a copy cannot dereference a symlink within the DIR to get to a
104 file outside the DIR.
105
106 The rrsync script rejects rsync's [`--protect-args`](rsync.1#opt) (`-s`) option
107 because it would allow options to be sent to the server-side that the script
108 cannot check.  If you want to support `--protect-args`, use a daemon-over-ssh
109 setup.
110
111 The rrsync script accepts just a subset of rsync's options that the real rsync
112 uses when running the server command.  A few extra convenience options are also
113 included to help it to interact with BackupPC and accept some convenient user
114 overrides.
115
116 The script (or a copy of it) can be manually edited if you want it to customize
117 the option handling.
118
119 ## BASH SECURITY ISSUE
120
121 If your users have bash set as their home shell, bash may try to be overly
122 helpful and ensure that the user's login bashrc files are run prior to
123 executing the forced command.  This can be a problem if the user can somehow
124 update their home bashrc files, perhaps via the restricted copy, a shared home
125 directory, or something similar.
126
127 One simple way to avoid the issue is to switch the user to a simpler shell,
128 such as dash.  When choosing the new home shell, make sure that you're not
129 choosing bash in disguise, as it is unclear if it avoids the security issue.
130
131 Another potential fix is to ensure that the user's home directory is not a
132 shared mount and that they have no means of copying files outside of their
133 restricted directories.  This may require you to force the enabling of symlink
134 munging on the server side.
135
136 A future version of openssh may have a change to the handling of forced
137 commands that allows it to avoid using the user's home shell.
138
139 ## EXAMPLES
140
141 The `~/.ssh/authorized_keys` file might have lines in it like this:
142
143 > ```
144 > command="rrsync client/logs" ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAzG...
145 > command="rrsync -ro results" ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAmk...
146 > ```
147
148 ## FILES
149
150 ~/.ssh/authorized_keys
151
152 ## SEE ALSO
153
154 [**rsync**(1)](rsync.1), [**rsyncd.conf**(5)](rsyncd.conf.5)
155
156 ## VERSION
157
158 This manpage is current for version @VERSION@ of rsync.
159
160 ## CREDITS
161
162 rsync is distributed under the GNU General Public License.  See the file
163 [COPYING](COPYING) for details.
164
165 An rsync web site is available at <https://rsync.samba.org/> and its github
166 project is <https://github.com/WayneD/rsync>.
167
168 ## AUTHOR
169
170 The original rrsync perl script was written by Joe Smith.  Many people have
171 later contributed to it.  The python version was created by Wayne Davison.