打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
修改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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
查找Linux版本命令很多且简单,详细使用方法详解如下
Linux服务器安全策略配置
utsname
linux发行版本查看命令
Linux下查看版本号的命令
(Linux基础知识)Linux版本的查看方法及版本命令
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服