Debian Codegraph @

README.md

raw symbols SCIP
1 # sudo-rs
2
3 A safety oriented and memory safe implementation of sudo and su written in Rust.
4
5 ## Status of this project
6
7 Sudo-rs is being actively maintained; features you might expect from original sudo
8 may still be unimplemented or not planned. Also note our [frequently asked questions](FAQ.md).
9
10 If there is an important one you need, please request it using the issue tracker. If you encounter any usability bugs,
11 also please report them on the [issue tracker](https://github.com/trifectatechfoundation/sudo-rs/issues).
12 Suspected vulnerabilities can be reported on our [security page](https://github.com/trifectatechfoundation/sudo-rs/security).
13
14 Sudo-rs has been audited twice: an audit of version 0.2.0 was performed in August 2023, and a second audit of version 0.2.8 in August 2025. The audit reports can be found [here](docs/audit).
15
16 Sudo-rs currently is targeted for FreeBSD and Linux-based operating systems only.
17
18 ## Installing sudo-rs
19
20 You can install sudo-rs using the package manager of your Linux distribution. Many Linux distributions will also keep
21 original sudo installed and so offer sudo-rs using modified command names. You can work around that by creating e.g. an `alias`, but that will
22 only change your own invocations of `sudo` to sudo-rs and not affect other programs and scripts that use `sudo`.
23
24 To avoid that and/or to get the latest version, you can use our prepackaged binaries (see below).
25
26 ### Ubuntu 25.10 (Questing Quokka) and 26.04 (Resolute Raccoon)
27
28 sudo-rs is installed and enabled by default; you can control which sudo version is being used by running
29
30 ```sh
31 update-alternatives --config sudo
32 ```
33
34 #### Versions
35 The sudo-rs package in Ubuntu 25.10 is based on v0.2.8 with additional bug fixes backported from newer versions.
36 The package in Ubuntu 26.04 LTS is based on v0.2.13 with additional bug fixes.
37
38 ### Arch Linux
39
40 sudo-rs can be installed from the distribution repositories:
41
42 ```sh
43 pacman -S sudo-rs
44 ```
45
46 This will offer the functionality using the commands `sudo-rs`, `sudoedit-rs`, `visudo-rs` and `su-rs` to avoid conflicts.
47
48 The sudo-rs package on Arch Linux is typically up-to-date.
49
50 ### Fedora
51
52 On Fedora you can use:
53
54 ```sh
55 dnf install sudo-rs
56 ```
57
58 This will offer the functionality using the commands `sudo-rs`, `visudo-rs` and `su-rs` to avoid conflicts.
59
60 The version packaged in Fedora is usually the latest.
61
62 ### Debian
63
64 If you are running Debian 13 (trixie) or later you can use:
65
66 ```sh
67 apt-get install sudo-rs
68 ```
69
70 This will offer the functionality using the commands `sudo-rs`, `visudo-rs`. If you want to invoke sudo-rs
71 via the usual commands `sudo` and `visudo` instead, prepend `/usr/lib/cargo/bin` to your current `$PATH` variable.
72
73 The sudo-rs version packaged in Debian 13 (trixie) is based on release 0.2.5 from April 2025 which is missing `sudoedit`, `NOEXEC:`,
74 and many other usability and compatibility improvements, but is up-to-date with respect to security patches. Due to a misconfiguration
75 in this package, `su-rs` cannot be used because it does not have the setuid flag set.
76
77 Debian unstable (sid) may have a newer version.
78
79 ### FreeBSD
80
81 We are maintaining the FreeBSD port of sudo-rs ourselves, which is available in the ports tree. Sudo-rs is available in two flavours:
82
83 ```sh
84 pkg install sudo-rs
85 ```
86
87 To get sudo-rs using the commands `sudo`, `visudo` and `sudoedit`. This conflicts with the `security/sudo` package and so you cannot have both
88 installed at the same time.
89
90 Alternatively,
91
92 ```sh
93 pkg install sudo-rs-coexist
94 ```
95
96 Installs the commands as `sudo-rs`, `visudo-rs`' and `sudoedit-rs` and does not conflict with the `security/sudo` package.
97
98 To run these commands, the `pkg` utility needs to be using the `2025Q4` quarterly version (or later) of the ports tree. To use the
99 absolute latest version, you can [switch from quarterly to `latest`](https://wiki.freebsd.org/Ports/QuarterlyBranch#How_to_switch_from_quarterly_to_latest).
100
101 ### NixOS
102
103 On NixOS sudo-rs can be installed by adding the following to your configuration:
104
105 ```nix
106 security.sudo-rs.enable = true;
107 ```
108
109 This will replace the usual `sudo` and `sudoedit` commands.
110
111 ### Alpine Linux
112
113 On Alpine Linux, sudo-rs is in the *community* repository, and can be installed as:
114
115 ```sh
116 apk add sudo-rs
117 ```
118
119 This will install the `sudo`, `visudo` and `sudoedit` commands (but not replace `su`, which is still offered through BusyBox).
120
121 ### Installing our pre-compiled x86-64 binaries
122
123 You can also switch to sudo-rs manually by using our pre-compiled tarballs.
124 We currently only offer these for x86-64 Linux systems.
125
126 We recommend installing sudo-rs and su-rs in your `/usr/local` hierarchy so it does not affect the integrity of the package
127 manager of your Linux distribution. You can achieve this using the commands:
128
129 ```sh
130 sudo tar -C /usr/local -xvf sudo-0.2.14.tar.gz
131 ```
132
133 and for su-rs:
134
135 ```sh
136 sudo tar -C /usr/local -xvf su-0.2.14.tar.gz
137 ```
138
139 This will install sudo-rs and su-rs in `/usr/local/bin` using the usual commands `sudo`, `visudo`, `sudoedit` and `su`. Please double check
140 that in your default `PATH`, the folders `/usr/local/bin` and `/usr/local/sbin` have priority over `/usr/bin` and `/usr/sbin`.
141
142 If you **don't** have Todd Miller's `sudo` installed, you also have to make sure that:
143
144 * You manually create a `/etc/sudoers` or `/etc/sudoers-rs` file, this could be as simple as:
145
146 Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
147
148 %sudo ALL=(ALL:ALL) ALL
149
150 `sudo-rs` will try to process `/etc/sudoers-rs` if it exists, otherwise it will use `/etc/sudoers`.
151 For an explanation of the sudoers syntax you can look at the
152 [sudoers man page](https://www.sudo.ws/docs/man/sudoers.man/).
153
154 * (Strongly recommended) You create `/etc/pam.d/sudo` and `/etc/pam.d/sudo-i` files that contain (for Debian/Ubuntu):
155
156 session required pam_limits.so
157
158 @include common-auth
159 @include common-account
160 @include common-session-noninteractive
161
162 If you don't do this, either a "fallback" PAM policy will be used or `sudo-rs` will simply refuse to run
163 since it cannot initialize PAM. On Fedora, the syntax for PAM configuration is slightly different, but the
164 correct PAM configuration files will most likely be already installed.
165 On FreeBSD, you may want to put these files in `/usr/local/etc/pam.d` instead.
166
167 ### Building from source
168
169 Sudo-rs is written in Rust. The minimum required Rust version is 1.85. If your
170 Linux distribution does not package that version (or a later one), you can always
171 install the most recent version through [rustup]. You also need the C development
172 files for PAM (`libpam0g-dev` on Debian, `pam-devel` on Fedora). If you want to
173 install translated messages, you also need gettext tools for `msgfmt` (`gettext`
174 on Debian and Ubuntu).
175
176 On Ubuntu or Debian-based systems, use the following command to install the PAM development library:
177
178 ```sh
179 sudo apt-get install libpam0g-dev
180 ```
181
182 On Fedora, CentOS and other Red Hat-based systems, you can use the following command:
183
184 ```sh
185 sudo yum install pam-devel
186 ```
187
188 With dependencies installed, building sudo-rs is a simple matter of:
189
190 ```sh
191 cargo build --release
192 ```
193
194 This produces a binary `target/release/sudo`. However, this binary must have
195 the setuid flag set and must be owned by the root user in order to provide any
196 useful functionality. Consult your operating system manual for details.
197
198 Sudo-rs then also needs the configuration files; please follow the installation
199 suggestions in the previous section.
200
201 ### Feature flags
202
203 #### --features pam-login
204
205 By default, sudo-rs will use the PAM service name `sudo`. On Debian and Fedora
206 systems, it is customary that the name `sudo-i` is used when the `-i / --login`
207 command line option is used. To get this behaviour, enable the `pam-login`
208 feature when building:
209
210 ```sh
211 cargo build --release --features pam-login
212 ```
213
214 This feature is enabled on our pre-supplied binaries.
215
216 #### --features apparmor
217
218 sudo-rs has support for selecting AppArmor profile on Linux distributions that
219 support AppArmor such as Debian and Ubuntu. To enable this feature, build sudo-rs
220 with apparmor support enabled:
221
222 ```sh
223 cargo build --release --features apparmor
224 ```
225
226 This feature is disabled on our pre-supplied binaries.
227
228 #### --features gettext
229
230 sudo-rs has support for translated user-facing messages. To enable this feature,
231 build sudo-rs with gettext support enabled:
232
233 ```sh
234 cargo build --release --features gettext
235 ```
236
237 You can install the translation files from `po/*.po` using:
238
239 ```sh
240 sudo make install-mo
241 ```
242
243 This uses `msgfmt` to compile each `<lang>.po` file to
244 `/usr/share/locale/<lang>/LC_MESSAGES/sudo-rs.mo`. If needed, you can override
245 the install location by setting `LOCALEDIR` when invoking `make`.
246
247 [rustup]: https://rustup.rs/
248
249 ## Differences from original sudo
250
251 sudo-rs supports less functionality than sudo. Some of this is by design. In
252 most cases you will get a clear error if you try something that is not
253 supported (e.g. use a configuration flag or command line option that is not
254 implemented).
255
256 Exceptions to the above, with respect to your `/etc/sudoers` configuration:
257
258 * `use_pty` is enabled by default, but can be disabled.
259 * `env_reset` is ignored --- this is always enabled.
260 * `visiblepw` is ignored --- this is always disabled.
261 * `pwfeedback` is enabled by default, but can be disabled.
262 * `verifypw` is ignored --- this is always set to `all` (the default)
263 * the (NO)PASSWD tag on the "list" pseudocommand will determine whether a password
264 is required for the `sudo -U --list` command, instead of `listpw`.
265 * `mail_badpass`, `always_set_home`, `always_query_group_plugin` and
266 `match_group_by_gid` are not applicable to our implementation, but ignored for
267 compatibility reasons.
268 * `timestamp_type` is always set at `tty`.
269 * `sudoedit_checkdir` is always `on`, and `sudoedit_follow` is always `off`.
270 * `logfile` is not supported --- logging is always done via syslog.
271
272 Some other notable restrictions to be aware of:
273
274 * Some functionality is not supported, such as preventing shell escapes using `INTERCEPT` and
275 storing config in LDAP using `sudoers.ldap`, and `cvtsudoers`. This includes `sudo -E`,
276 which is [discouraged](https://www.sudo.ws/docs/troubleshooting/#why-does-sudo-modify-the-commands-environment) in original sudo.
277 * Sudo-rs always uses PAM for authentication, so your system must be set up for PAM.
278 Sudo-rs will use the `sudo` and `sudo-i` service configuration. This also means
279 that resource limits, umasks, etc have to be configured via PAM and not through
280 the sudoers file.
281 * sudo-rs will not include the sendmail support of original sudo.
282 * The sudoers file must be valid UTF-8.
283 * To prevent a common configuration mistake in the sudoers file, wildcards
284 are only supported in *argument positions* for a command as the final argument.
285 E.g., `%sudoers ALL = /sbin/fsck*` will allow `sudo fsck` and `sudo fsck_exfat` as expected,
286 and `%sudoers ALL = /sbin/service ntp *` will allow a user to control the `ntp` service.
287 but `%sudoers ALL = /bin/rm *.txt` will not allow an operator to run `sudo rm README.txt`,
288 nor `sudo rm -rf /home .txt`, as with original sudo.
289
290 If you find a common use case for original sudo missing, please create a feature
291 request for it in our issue tracker.
292
293 ## Aim of the project
294
295 Our current target is to build a drop-in replacement for all common use cases of
296 sudo. For the sudoers config syntax this means that we support the default
297 configuration files of common Linux distributions. Our implementation should support
298 all commonly used command line options from the original sudo implementation.
299
300 Some parts of the original sudo are explicitly not in scope. Sudo has a large
301 and rich history and some of the features available in the original sudo
302 implementation are largely unused or only available for legacy platforms. In
303 order to determine which features make it we both consider whether the feature
304 is relevant for modern systems, and whether it will receive at very least
305 decent usage. Finally, of course, a feature should not compromise the safety of
306 the whole program.
307
308 Our `su` implementation is made using the building blocks we created for our
309 sudo implementation. It is a suitable replacement for the `su` distributed
310 by [util-linux].
311
312 [util-linux]: https://github.com/util-linux/util-linux
313
314 ## Future work
315
316 While our initial target is a drop-in replacement for most basic use cases of
317 sudo, our work may evolve beyond that target. We are also looking into
318 alternative ways to configure sudo without the sudoers config file syntax and to
319 extract parts of our work in usable crates for other people.
320
321 ## History
322
323 The initial development of sudo-rs was started and funded by the [Internet Security Research Group](https://www.abetterinternet.org/) as part of the [Prossimo project](https://www.memorysafety.org/)
324
325 ## Acknowledgements
326
327 Sudo-rs is an independent implementation, but it incorporates documentation and Rust translations of code from [sudo](https://www.sudo.ws/), maintained by Todd C. Miller. We thank Todd and the other sudo contributors for their work.
328
329 An independent security audit of sudo-rs was made possible by the [NLNet Foundation](https://nlnet.nl/), who also [sponsored](https://nlnet.nl/project/sudo-rs/) work on increased compatibility with the original sudo and the FreeBSD port.
330
331 The sudo-rs project would not have existed without the support of its sponsors, a full overview is maintained at <https://trifectatech.org/initiatives/privilege-boundary/>