You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

OCI: Sudo Command Returns "sorry, you are not allowed to preserve the environment" error

edited Apr 21, 2025 3:27PM in Linux

Applies To:

Oracle Cloud Infrastructure

Oracle Linux

Symptoms

Running sudo command with "-E" option reports the following error.

    $ export MY_NAME=abcd
    $ sudo -E bash -c 'echo $MY_NAME'
    sudo: sorry, you are not allowed to preserve the environment

The following sudo rule exists for the user in /etc/sudoers file.

oracle ALL=(ALL) NOPASSWD: /usr/bin/bash

Cause

The sudo rule has not defined to present the environment variables of the user.

Solution

Add SETENV tag to the user sudo rule entry to fix the issue.

#visudo
oracle    ALL=(ALL)       NOPASSWD:SETENV: /usr/bin/bash *

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!