Display a message while prompting for sudo password
Solution 1
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
Solution 2
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:
#!/bin/bash
sudo(){
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.
Related videos on Youtube
John Smith
Updated on September 18, 2022Comments
-
John Smith over 1 year
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?
-
sudo about 7 yearsLove how it's called "lecture." macOS gives you a lecture about abusing power when you first use sudo.
-
Nonny Moose almost 7 years@sudo So does Ubuntu, at least in some situations.
-
lotfio over 6 years@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 -
storm over 5 years@ABDELLATIFLAKEHAL :
lecture = never