I had once seen a Ubuntu user use a sudo command in a terminal. Before he was prompted for a password he was shown the following message:

user1@linuxbox:~$ sudo apt-get update
Please do not run this command if you have not been granted sudo rights.
[sudo] password for user1:

I would like to display a similar message on my system when a user runs a sudo command. What must I edit/change to display a similar message when a user runs a sudo command on the terminal?


See if your sudo supports lecture_file option

man sudoers | grep lecture_file

This is what man sudoers says in my case :

lecture_file Path to a file containing an alternate sudo lecture that will be used in place of the standard lecture if the named file exists. By default, sudo uses a built-in lecture.

So, to change the text, add it to a file e.g /etc/sudoers.lecture and point to it from /etc/sudoers :

Defaults        lecture_file = /etc/sudoers.lecture

To display the lecture on every invocation of sudo also add the following to /etc/sudoers:

Defaults        lecture = always
| improve this answer | |
  • 1
    Love how it's called "lecture." macOS gives you a lecture about abusing power when you first use sudo. – sudo Mar 10 '17 at 22:22
  • @sudo So does Ubuntu, at least in some situations. – Nonny Moose May 26 '17 at 23:23
  • @storm and how to turn it off iam using debian stretch and the sudo message is displayed by default i tryed using something like lecture = off but it's not recognized – lotfio Sep 30 '17 at 19:20
  • @ABDELLATIFLAKEHAL : lecture = never – storm Dec 6 '18 at 15:22

Write a "wrapper script" around the sudo command.

Basically, you replace the standard sudo command with a script that contains a function called sudo(). This function first echoes your custom message, then calls the standard sudo command /usr/bin/sudo.

This script would be something like:

        echo "This is a custom message."
        /usr/bin/sudo "$@"

You need to make sure the script is in the path of the user. Here (under "Putting it all together") is a good explanation of how to do this. Google "wrapper script" for other examples.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.