I just read another time that post : Where are sudo's insults stored?

But I just have a beautiful question about these insults :

Can we add new ones by adding another files (instead of modificating an header inside plugins/sudoers)?

Current sudo insults files are :

  • ins_2001.h
  • ins_classic.h
  • ins_csops.h
  • ins_goons.h
  • insults.h
  • 1
    Are you trying to avoid having to recompile sudo? Or do you just want to add insults in your own, separate header file? (sudo doesn't read insults from those .h files when you run it--the files are used during compilation.) You may want to edit your question to clarify this. – Eliah Kagan Nov 14 '19 at 17:49
  • @EliahKagan not at all, I want to know how I could add custom insults – damadam Nov 14 '19 at 19:41
  • @damadam You can easily add custom insults without recompiling the kernel as accepted answer states. I've added an answer and tested it. Proof is all their for peer review. – WinEunuuchs2Unix Nov 15 '19 at 1:02

No, you cannot simply 'add' insults to a directory and expect them to work. The only way to add new insults is to recompile sudo so that it includes those insults at compile time.

The link from your question (Where are sudo's insults stored?) explains what those files are:

The file insults.h contains compiler instructions on which of the above insults to include in the compiled kernel. Indeed, you could create your own insults file, add the name to insults.h and recompile...

But you WILL need to add insults and then recompile to include them. Doing this, however, will mean you have to recompile sudo if there's security updates, etc. and it's likely this can cause security issues down the road if you don't recompile with security patches included.

  • nice answer, now i'm curious about how we can recompile sudo – damadam Nov 14 '19 at 19:43
  • 1
    @damadam ... which is a different question than you asked ;) – Thomas Ward Nov 14 '19 at 19:44

You can add new insults only by replacing existing insults of equal or greater length.

From the second answer in your link are these phrases:

ins_2001.h (2001 Space Odyssey insults):

 * HAL insults (paraphrased) from 2001.

"Just what do you think you're doing Dave?",
"It can only be attributed to human error.",

Find the file

$ grepall "Just what do you think you're doing Dave?"
Binary file /usr/lib/sudo/sudoers.so matches

OK we now know the file name. That was the easy part.

Backup the file

First make a backup (because we always remember to do that right?):

$ sudo cp -a /usr/lib/sudo/sudoers{.so,.so.bak}

$ ll /usr/lib/sudo/sudoers{.so,.so.bak}
-rw-r--r-- 1 root root 316768 Oct 11 06:01 /usr/lib/sudo/sudoers.so
-rw-r--r-- 1 root root 316768 Oct 11 06:01 /usr/lib/sudo/sudoers.so.bak

Make the script

Then make our script called sudoinsults:


# NAME: sudoinsult
# PATH: $HOME/askubuntu/
# DESC: For: https://askubuntu.com/questions/1188779/adding-new-sudo-insults
# DATE: November 14, 2019.

# NOTE: Change sudo insults to personal favorites

# Build array of insults from disk
IFS=$'\n' Arr=( $(cat sudoinsult.txt) )

# Initialize variables
Spaces="                                                                     "
Spaces="$Spaces""                                                            "

[[ ${#Arr[@]} -gt 0 ]] && upper=$(( ${#Arr[@]} - 1 ))
[[ $upper -gt 0 ]] && for (( i=0; i<upper; i=i+2 )) ; do
    Search="${Arr[i]}"      # Move array indices to named variables
    Replace="${Arr[i+1]}"   #  for a simpler life.

    printf "Replacing: '%s'\n     With: '%s'\n" "$Search" "$Replace"
    if [[ "${#Search}" -lt "${#Replace}" ]] ; then
        echo "Replacement can't be longer than original"
    elif [[ "${#Search}" -lt 8 ]] ; then
        echo "Original insult cannot be less than 8 characters"
    elif [[ "${#Search}" -gt "${#Spaces}" ]] ; then
        echo "Original insult cannot be longer than ${#Spaces} characters"
    elif [[ "${#Replace}" -lt 1 ]] ; then
        echo "Replacement insult cannot be less than 1 character"
    elif ! grep "$Search" "$File" >/dev/null ; then
        echo "Search insult not found in $File"

    # Pad replacement with spaces as needed.
    ReplaceS="$Replace${Spaces:0:$((${#Search} - ${#Replace}))}"
    [[ "${#ReplaceS}" -ne "${#Search}" ]] && \
        { echo Internal error ReplaceS different length than Search; exit; }

# Looks wrong: https://unix.stackexchange.com/a/354493/200094
#y="${y:0:40}${forty:0:$((40 - ${#y}))}"
#echo "'${y}'"
    sed -i "s/$Search/$ReplaceS/" "$File"
    (( InsultCount++ ))


if [[ $upper -gt 0 ]] ; then
    echo "$InsultCount Insults replaced."
    echo "Insult file (sudoinsult.txt) does not exist or only has one line." >2

Create the datafile

Hopefully no need to explain how to create a text file (hint: gedit)

$ cat sudoinsult.txt

Just what do you think you're doing Dave?
Just what do you think you're doing Rick?
It can only be attributed to human error.
It can only be attributed to the beer.

Run the script and check results

$ sudo ./sudoinsult

Replacing: 'Just what do you think you're doing Dave?'
     With: 'Just what do you think you're doing Rick?'
Replacing: 'It can only be attributed to human error.'
     With: 'It can only be attributed to the beer.'
2 Insults replaced.

$ ll /usr/lib/sudo/sudoers{.so,.so.bak}

-rw-r--r-- 1 root root 316768 Nov 14 17:43 /usr/lib/sudo/sudoers.so
-rw-r--r-- 1 root root 316768 Oct 11 06:01 /usr/lib/sudo/sudoers.so.bak

$ grep "Just what do you think you're doing Rick?" /usr/lib/sudo/sudoers.so

Binary file /usr/lib/sudo/sudoers.so matches

$ grep "It can only be attributed to the beer." /usr/lib/sudo/sudoers.so

Binary file /usr/lib/sudo/sudoers.so matches

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.