修改Linux登录欢迎提示信息

之前登陆某服务器,见到了花式的欢迎信息,然后,就很想试试~

服务器一般可以配置两种类型的提示信息:①用户登录前显示的提示信息;②用户成功登录后显示的提示信息。需注意的是,不同的linux发行版本修改的方法不太一样。
大致过程如下:
(1) 查看服务器的基本信息
uname -a #查看服务器的基本信息
可以看到,是熟悉的Ubuntu~
(2) 修改登录欢迎信息
在一般的linux发行版中(如centos),/etc/issue里存放了用户成功登录前显示的信息;/etc/motd存放了用户成功登录后显示的信息;但在Ubuntu中,相关的是/etc/update-motd.d/文件夹下的几个脚本:
cd /etc/update-motd.d/ls -alF
通过ssh登录主机/服务器时,会输出/var/run/motd.dynamic 中的信息。而/var/run/motd.dynamic 中的信息就是用户登录时系统已root身份执行上述/etc/update-motd.d/ 下面的几个脚本所生成的。所以想要DIY欢迎信息,就需要修改这几个脚本文件。
cat /var/run/motd.dynamic #查看当前的登录提示语
修改前的提示语,嗯,还蛮老干部的,为了留个纪念,我决定给备个份,毕竟之后就看不到了。值得注意的是,修改系统配置文件要谨慎。
sudo cp /var/run/motd.dynamic{,.bak} #生成备份文件motd.dynamic.bak
结合脚本文件的名字和提示语的各部分内容,可以大致推断出需作出的修改。其中,00-header主要是显示一些欢迎信息的头部;10-help-text中主要是一些提供帮助查询网站的信息。其它还有一些软件包更新、系统更新等信息,本文主要以前两个脚本文件为例。
查看00-header脚本文件:
cat /etc/update-motd.d/00-header#!/bin/sh## 00-header - create the header of the MOTD# Copyright (C) 2009-2010 Canonical Ltd.## Authors: Dustin Kirkland <kirkland@canonical.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.[ -r /etc/lsb-release ] && . /etc/lsb-releaseif [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then # Fall back to using the very slow lsb_release utility DISTRIB_DESCRIPTION=$(lsb_release -s -d)fiprintf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"
查看10-help-text文件:
cat /etc/update-motd.d/10-help-text#!/bin/sh## 10-help-text - print the help text associated with the distro# Copyright (C) 2009-2010 Canonical Ltd.## Authors: Dustin Kirkland <kirkland@canonical.com>,# Brian Murray <brian@canonical.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
printf "\n"printf " * Documentation: https://help.ubuntu.com\n"printf " * Management: https://landscape.canonical.com\n"printf " * Support: https://ubuntu.com/advantage\n"
大致了解脚本文件长什么样子了,就可以开始修改了。其实,主要修改00-header脚本文件就可以啦,帮助文件10-help-text的4行内容直接注释掉就好了,没必要展示。
#为防止改崩了或者改丑了,先给这些系统文件创建备份sudo cp /etc/update-motd.d/00-header{,.bak}sudo cp /etc/update-motd.d/10-help-text{,.bak}
sudo vim /etc/update-motd.d/10-help-text #修改10-help-text脚本文件sudo vim /etc/update-motd.d/00-header #修改00-header脚本文件
#!/bin/sh## 00-header - create the header of the MOTD# Copyright (C) 2009-2010 Canonical Ltd.## Authors: Dustin Kirkland <kirkland@canonical.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then # Fall back to using the very slow lsb_release utility DISTRIB_DESCRIPTION=$(lsb_release -s -d)fiprintf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"printf "\n"printf "########################## Softwares installed #############################"printf "\n# `ls /home/hucy/.soft | sort | paste -s -d / `\n"printf "############################################################################"
本例仅简单增加了4行,目的是在登录成功后,显示已安装的软件。注:/home/hucy/.soft目录下,是给所有安装成功的软件创建的软链接。
修改后,登录成功后的界面如下:
修改后的界面比较丑,但是基本达到了目的。总归是别人家的服务器,就改到这里吧~

参考阅读:

1. CentOS查看系统信息命令和方法 https://www.cnblogs.com/kluan/p/4457889.html

2. 教你如何修改Linux远程登录欢迎提示信息 https://www.jb51.net/article/136267.htm

3. Ubuntu修改ssh登录欢迎信息 https://blog.csdn.net/plm199513100/article/details/81270377

(0)

相关推荐

  • 如何写gdb命令脚本

    作为UNIX/Linux下使用广泛的调试器,gdb不仅提供了丰富的命令,还引入了对脚本的支持:一种是对已存在的脚本语言支持,比如python,用户可以直接书写python脚本,由gdb调用python ...

  • 香橙派OrangePi 3开发板在Linux系统下修改Framebuffer 宽度和高度的方法

    注意:此方法只适用于 linux4.9 内核的系统,linux5.4 内核的系统无法使用 1) 在 linux 系统的/boot/orangepiEnv.txt 中有 fb0_width 和 fb0_ ...

  • passwd修改用户密码注意什么?linux运维命令

    passwd命令可以修改用户密码及密码过期时间等内容,是Linux运维管理工作中很常用的命令.普通用户和超级用户都可以运行passwd命令,但普通用户只能更改自身的用户密码,超级用户root则可以设置 ...

  • Linux修改用户信息的usermod命令参数选项有什么?

    usermod命令用于修改系统已经存在的用户的账号信息.想要成为优秀的Linux运维工程师,Linux基础命令的掌握是必须的.而核心命令中,修改用户信息的usermod命令是非常重要的,那么修改用户信 ...

  • 竟然无法登录,修改电脑用户登录密码后

    你用pe进入系统删除密码吧,不用那么麻烦的win7登录密码,我说个方法你试一下win7登录密码,开机的时候按F8(不停的按)选择"带命令提示的安全模示"竟然无法登录,修改电脑用户登 ...

  • putty登录远程linux系统

    putty登录远程linux系统 步骤一:双击打开Putty软件. 步骤二:在主机名称文本框中输入远程服务器的IP地址,SSH远程服务端口号一般默认是22,端口号有修改过请填写修改后的端口,连接类型选 ...

  • linux centos修改root密码

    linux centos修改root密码 步骤一:使用putty或其他远程终端工具登录root用户到服务器,在命令行输入passwd命令,回车. 步骤二:这里提示让输入新的密码,输入新的密码,注意这里 ...

  • 宝塔Linux面板如何修改默认的SSH端口号

    宝塔Linux面板如何修改默认的SSH端口号 步骤一:登录到宝塔面板,在左侧菜单栏找到并打开安全菜单,找到SSH端口号,默认端口号是22,输入新的端口号,点击更改,需要注意的是如果购买的服务器有安全组 ...

  • Linux(CentOS 7)修改max open files的值

    阅读目录 系统全局参数file-max 如果是系统服务 临时修改,重启后失效,不对运行中程序生效 永久修改,需要重启系统 动态修改运行中程序的值 新安装的linux系统允许每个程序的最大打开文件数默认 ...

  • 宝塔面板如何修改登录用户名

    宝塔面板如何修改登录用户名