edgeport - v1.0.3
    Preparing search index...

    Function sudo

    • Runs a command under sudo on an already-open session and collects its output.

      Internally runs sudo -S -p '' <command>, writes password followed by a newline to the command's stdin (where -S makes sudo read it), sends EOF, then collects stdout/stderr and the exit code.

      Caveats:

      • the remote sudoers policy must allow password sudo and not require a tty (requiretty off - the default on most modern distros)
      • command is interpreted by the remote login shell, so quote/escape it as you would on a shell command line

      Parameters

      • session: SshSession

        An open, authenticated SSH session.

      • command: string

        The command to run under sudo (interpreted by the remote shell).

      • opts: SudoOptions

        Sudo options; password is the user's sudo password.

      Returns Promise<ExecResult>

      The command's stdout, stderr, and exit code (0 on clean exit).

      If the channel cannot be opened.

      If the server rejects the exec request.

      1.0.2

      import { connect, sudo } from 'edgeport/ssh';

      await using ssh = await connect({ hostname: 'h', username: 'u', password: env.PW });
      const { stdout, code } = await sudo(ssh, 'systemctl restart myapp', { password: env.PW });
      console.log(code, new TextDecoder().decode(stdout));