# su-exec

> Run an executable as root, similar to `sudo` in linux.

Latest version **0.1.5** (published 2015-10-04) · 0 weekly downloads

## Install

```sh
npm install su-exec
pnpm add su-exec
yarn add su-exec
bun add su-exec
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2015-10-04 |
| First published | 2015-06-04 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | LastLeaf |
| Maintainers | lastleaf |

## Links

- npm: https://www.npmjs.com/package/su-exec
- Repository: https://github.com/LastLeaf/su-exec
- Issues: https://github.com/LastLeaf/su-exec/issues
- npm.io page: https://npm.io/package/su-exec

## Recent versions

- 0.1.5 (latest) — 2015-10-04
- 0.1.4 — 2015-06-05
- 0.1.3 — 2015-06-05
- 0.1.1 — 2015-06-05
- 0.1.0 — 2015-06-04

## README

# su-exec #

This linux node.js module make it simple to execute outer executable with root privilege, similar to `sudo`.

This module requires root when initializing, so your app should be started as root.
Do NOT forget to drop root privilege using `process.setuid()` and `process.setgid()`.

It keeps a tiny background process to get root privilege, living with the current node process.

## How to Use ##

Install with `npm install su-exec`.

It should be initialized with `suExec.init()` once before used. The node process should has root privilege at that moment.

Then exec with `suExec.execFile(file, argv, options, cb)`, or `suExec.execPath(file, argv, options, cb)`.
The `execPath` method could search executables in PATH (just like what shell does).

```js
var suExec = require('su-exec');

suExec.init();

process.setgid('nogroup');
process.setuid('nobody');

suExec.execFile('/usr/bin/whoami', ['/usr/bin/whoami'], {
	stdin: '/dev/null',
	stdout: '/dev/null',
	stderr: '/dev/null'
}, function(err, status, signal){
	// execute when child exit
});
```

Available options are `stdin`, `stdout`, and `stderr`, indicating the files which should be redirected.
They are "/dev/null" by default.

There is also a `suExec.destroy()` to end the background root process.

## LICENSE ##

MIT

---
_Source: https://npm.io/package/su-exec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
