命令行乐趣:嘲讽输错Bash命令的用户

系统 Linux
你可以通过配置 sudo 命令去嘲讽输入错误密码的用户。但是现在,当用户在 shell 输错命令时,就能嘲讽他了(滥用?)。

[[224460]]

你可以通过配置 sudo 命令去嘲讽输入错误密码的用户。但是现在,当用户在 shell 输错命令时,就能嘲讽他了(滥用?)。

 

你好 bash-insulter

来自 Github 页面:

当用户键入错误命令,随机嘲讽。它使用了一个 bash4.x. 版本的全新内置错误处理函数,叫 command_not_found_handle

 

安装

键入下列 git 命令克隆一个仓库:

  1. git clone https://github.com/hkbakke/bash-insulter.git bash-insulter

示例输出:

  1. Cloning into 'bash-insulter'...
  2. remote: Counting objects: 52, done.
  3. remote: Compressing objects: 100% (49/49), done.
  4. remote: Total 52 (delta 12), reused 12 (delta 2), pack-reused 0
  5. Unpacking objects: 100% (52/52), done.

用文本编辑器,比如说使用 vi,编辑你的 ~/.bashrc 或者 /etc/bash.bashrc 文件:

  1. $ vi ~/.bashrc

在其后追加这一行(具体了解请查看 if..else..fi 声明source 命令):

  1. if [ -f $HOME/bash-insulter/src/bash.command-not-found ]; then
  2. source $HOME/bash-insulter/src/bash.command-not-found
  3. fi

保存并关闭文件。重新登录,如果不想退出账号也可以手动运行它:

  1. $ . $HOME/bash-insulter/src/bash.command-not-found

 

如何使用它?

尝试键入一些无效命令:

  1. $ ifconfigs
  2. $ dates

示例输出:

一个有趣的 bash 钩子功能,嘲讽输入了错误命令的你。

一个有趣的 bash 钩子功能,嘲讽输入了错误命令的你。

 

自定义

你需要编辑 $HOME/bash-insulter/src/bash.command-not-found

  1. $ vi $HOME/bash-insulter/src/bash.command-not-found

示例代码:

  1. command_not_found_handle () {
  2. local INSULTS=(
  3. "Boooo!"
  4. "Don't you know anything?"
  5. "RTFM!"
  6. "Hahaha, n00b!"
  7. "Wow! That was impressively wrong!"
  8. "What are you doing??"
  9. "Pathetic"
  10. "...and this is the best you can do??"
  11. "The worst one today!"
  12. "n00b alert!"
  13. "Your application for reduced salary has been sent!"
  14. "lol"
  15. "u suk"
  16. "lol... plz"
  17. "plz uninstall"
  18. "And the Darwin Award goes to.... ${USER}!"
  19. "ERROR_INCOMPETENT_USER"
  20. "Incompetence is also competence"
  21. "Bad."
  22. "Fake it till you make it!"
  23. "What is this...? Amateur hour!?"
  24. "Come on! You can do it!"
  25. "Nice try."
  26. "What if... you type an actual command the next time!"
  27. "What if I told you... it is possible to type valid commands."
  28. "Y u no speak computer???"
  29. "This is not Windows"
  30. "Perhaps you should leave the command line alone..."
  31. "Please step away from the keyboard!"
  32. "error code: 1D10T"
  33. "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
  34. "Pro tip: type a valid command!"
  35. )
  36.  
  37. # 设置“随机”种子发生器
  38. RANDOM=$(date +%s%N)
  39. VALUE=$((${RANDOM}%2))
  40.  
  41. if [[ ${VALUE} -lt 1 ]]; then
  42. printf "\n $(tput bold)$(tput setaf 1)$(shuf -n 1 -e "${INSULTS[@]}")$(tput sgr0)\n\n"
  43. fi
  44.  
  45. echo "-bash: $1: command not found"
  46.  
  47. # 无效命令,常规返回已存在的代码
  48. return 127
  49. }

 

赠品:sudo 嘲讽

编辑 sudoers 文件:

  1. $ sudo visudo

追加下面这一行:

  1. Defaults insults

或者像下面尾行增加一句嘲讽语:

  1. Defaults !lecture,tty_tickets,!fqdn,insults

这是我的文件:

  1. Defaults env_reset
  2. Defaults mail_badpass
  3. Defaults secure_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
  4. ## If set, sudo will insult users when they enter an incorrect password. ##
  5. Defaults insults
  6.  
  7. # Host alias specification
  8.  
  9. # User alias specification
  10.  
  11. # Cmnd alias specification
  12.  
  13. # User privilege specification
  14. root ALL = (ALL:ALL) ALL
  15.  
  16. # Members of the admin group may gain root privileges
  17. % admin ALL = (ALL) ALL  
  18.  
  19. # Allow members of group sudo to execute any command
  20. % sudo ALL = (ALL:ALL) ALL  
  21.  
  22. # See sudoers(5) for more information on "#include" directives:
  23.  
  24. #includedir /etc/sudoers.d

试一试:

  1. $ sudo -k # 清除缓存,从头开始
  2. $ sudo ls /root/
  3. $ sudo -i

样例对话:

当输入错误密码时,你会被一个有趣的的 sudo 嘲讽语戏弄。

当输入错误密码时,你会被一个有趣的的 sudo 嘲讽语戏弄。

 

赠品:你好 sl

sl 或是 UNIX 经典捣蛋软件 游戏。当你错误的把 ls 输入成 sl,将会有一辆蒸汽机车穿过你的屏幕。

  1. $ sl

Linux / UNIX 桌面乐趣: 蒸汽机车

Linux / UNIX 桌面乐趣: 蒸汽机车 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2017-05-25 10:32:40

命令linux系统

2009-12-25 17:05:09

LINUX Bash

2018-08-22 09:40:27

2010-06-23 14:28:23

LINUX Bash

2012-05-14 11:20:13

Hyper-VPowerShell

2014-10-31 10:50:28

Linux命令行工具

2019-10-12 10:12:13

Bash命令行Linux

2014-06-17 10:02:58

Bash Getopt命令行

2015-07-01 09:15:46

linuxQuora命令行

2020-12-20 17:34:50

Linux命令行终端

2023-06-25 12:00:53

2010-11-24 15:16:12

MySQL命令行登陆

2018-03-29 08:30:48

Linux命令BASH

2020-12-11 06:44:16

命令行工具开发

2020-12-10 16:16:08

工具代码开发

2015-06-16 10:36:45

Linux命令行

2021-08-30 07:50:42

脚本语言命令行

2010-11-16 13:40:52

Oracle命令行

2009-10-26 18:09:31

Oracle用户解锁

2010-10-12 17:08:16

MySQL命令行
点赞
收藏

51CTO技术栈公众号