edgeport - v1.0.3
    Preparing search index...

    Function sudoExec

    • One-shot: connects a session, runs a command under sudo, and closes the session.

      Credential reuse: sudoPassword defaults to password from the connect options - the common case where the login user's password is also their sudo password. Override it when the sudo password differs, or when you authenticate by key and must still supply a sudo password. If neither sudoPassword nor password is set, throws.

      Same caveats as sudo: the credential-reuse default only makes sense when the SSH login password is also the sudo password; the remote sudoers policy must allow password sudo without a tty; command is interpreted by the remote shell.

      Parameters

      • opts: SshConnectOptions & { command: string; sudoPassword?: string }

        Connect options plus the command to run and an optional sudoPassword.

      Returns Promise<ExecResult>

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

      If no sudo password is available (sudoPassword and password both unset).

      If the connection or handshake fails.

      If authentication is rejected.

      1.0.2

      import { sudoExec } from 'edgeport/ssh';

      // reuse the SSH login password as the sudo password
      const { stdout, code } = await sudoExec({
      hostname: 'h',
      username: 'u',
      password: env.PW,
      command: 'id -u'
      });
      console.log(code, new TextDecoder().decode(stdout).trim()); // 0 "0"