Strovent SystemsSign in
Reference

IBM i equivalent of sudo: SBMJOB USER, adopted authority and profile swaps

IBM i has no sudo at the command line. Submit a batch job with SBMJOB USER(name), use a program that adopts its owner's authority, or sign on as that user.

There is no sudo or runas command on the IBM i command line. A job runs with the authority of its user profile. To do something as another profile, you have four choices.

1. Sign on as that user

The plain way: start a second 5250 session and sign on with that profile's own user ID and password. Everything you do is recorded under that profile.

2. Submit a batch job as that user: SBMJOB USER

SBMJOB puts a command on a job queue to run as a batch job. Its USER parameter names the profile the job runs under:

SBMJOB CMD(CLRPFM FILE(APPLIB/WORKFILE)) JOB(CLEARWORK) USER(APPOWNER)
  • You need *USE authority to the user profile you name, as well as to the command and the job description.
  • Some IBM-supplied profiles are never allowed here, including QSECOFR, QSYS and QSPL.
  • The job runs later, in batch, not on your screen. Follow it with WRKSBMJOB. Its messages are in the job log, and any printed output goes to that job's spooled files.
  • On IBM i 7.6 an administrator can protect a profile from being used this way with the function usage QIBM_RUN_UNDER_USER_NO_AUTH set to *DENIED. Then SBMJOB USER() naming that profile is refused.

3. A program that adopts its owner's authority

An administrator can create or change a program with USRPRF(*OWNER). While that program runs, IBM i adds the authority of the program's owner, including the owner's special authorities such as *ALLOBJ, to yours. This is how applications let you change a file you could not change with SQL or a command.

Limits, from IBM's description:

  • Adopted authority lasts only while the program is in the call stack. Programs it calls can use it; a program started with TFRCTL cannot.
  • A job submitted from that program does not get the adopted authority.
  • It is not used for files in the integrated file system, such as /home or QOpenSys.
  • It is suspended while you use System Request, the Attn key program, or debug.
  • Only authority is adopted. Other profile attributes, such as limited capabilities, are not.
  • Objects you create are owned by you (or your group profile), not by the program owner.

DSPPGM shows whether a program adopts (the User profile value). IBM recommends that the owner of such programs has LMTCPB(*YES), so a command line reached by mistake does not run with the owner's authority.

4. A program that swaps profiles

Programs can change the user of the running job with IBM's APIs, for example Get Profile Handle (QSYGETPH) followed by Set Profile (QWTSETP). You do not type these at a command line; they are used inside applications and tools. IBM notes that a user with *ALLOBJ, or with private authority to the target user profile, can do this with no password for the target profile.

Whose name is on the work

With SBMJOB USER() and with a profile swap, the audit journal records the target profile, not you. With adopted authority, the job still runs as you.

If you hit an authority error and none of this is set up, the fix is a grant from your administrator. See IBM i "Not authorized" messages, CPF9802, CPF2182 and CPF9820.

Sources

Spotted a mistake? Email [email protected].