sudo returns "sorry, you are not allowed to preserve the environment" error

Solution Verified - Updated -

Issue

sudo returns sorry, you are not allowed to preserve the environment error:

  1. Run sudo with -E option to preserve their existing environment variables.

    $ export MY_NAME=foobar
    $ sudo -E bash -c 'echo $MY_NAME'
    sudo: sorry, you are not allowed to preserve the environment
    
  2. Below sudo rule exists for the user

    bob    ALL=(ALL)       NOPASSWD: /usr/bin/bash *
    

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
    • sudo

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content