Jonas
发布于 2024-06-17 / 13 阅读
0
0

修改Linux系统Banner自定义登录信息提示

修改Linux系统Banner自定义登录信息提示

终端提示信息分为:登陆前提示信息;登陆后提示信息。

有三种配置文件

  1. /etc/issue

  2. /etc/issue.net

  3. /etc/update-motd.d/ (目录)

本地终端登录信息 (登录前提示信息) ,配置文件 /etc/issue 作用

  • 只对本地用户登录有效(远程登录无效),在提示输入用户名上方的提示信息配置文件(如上图实例)

  • 转移字符作用

    转义符

    作用

    \d

    显示当前系统日期

    \s

    显示操作系统名称

    \l

    显示登录终端号(这个比较有用)

    \m

    显示硬件体系结构(如 i386\i686)

    \n

    显示主机名

    \o

    显示域名

    \r

    显示内核版本

    \t

    显示当前系统时间

    \u

    显示当前登录用户的序列号

  • 查看 /etc/issue\n 表示 显示主机名\l 表示 显示登录终端号

root@onecloud:~# cat /etc/issue.net
Armbian 23.02.0-trunk Jammy

远程终端信息(笔者这个也是登录后提示信息,有的系统是登录前信息),配置文件 /etc/issue.net

  • 对远程登录有效,在提示输入用户名后提示信息配置文件(Ubuntu 系统,在配置文件中添加 Training issue.net

  • 上一个转移字符表在 /etc/issue.net 文件中不能使用

  • 是否显示此提示信息,由 ssh 配置文件 /etc/ssh/ssh_config 决定(Ubuntu 是 /etc/ssh/shhd_config),加入 Banner /etc/issue.net 行才能显示(重启 SSH 服务 service sshd restart

登录后信息,配置文件 /etc/motd(Ubuntu 是 /etc/update-motd.d 目录)

  • 不管是本地登录,还是远程登录,都可以显示信息。此提示信息是登陆后的提示信息。

  • Ubuntu 系统是 /etc/update-motd.d 目录下的文件对终端登录后的提示信息

root@onecloud:~# ls -l /etc/update-motd.d/
total 32
-rw-r--r-- 1 root root 2477 Feb  2  2023 10-armbian-header
-rw-r--r-- 1 root root 6698 Feb  2  2023 30-armbian-sysinfo
-rw-r--r-- 1 root root 1019 Feb  2  2023 35-armbian-tips
-rw-r--r-- 1 root root 1252 Feb  2  2023 40-armbian-updates
-rw-r--r-- 1 root root  895 Feb  2  2023 41-armbian-config
-rw-r--r-- 1 root root  554 Feb  2  2023 98-armbian-autoreboot-warn
-rw-r--r-- 1 root root  451 Jun 16 06:47 quotes.txt

2024/06/23更新:

最近测试Armbian使用的是/run/pam.d/sshd文件来指定MOTD文件的位置。

经测试第一个motd=/run/motd.dynamic文件是无法修改的(更正,可以被/etc/updated-motd.d/目录中的脚本文件自动修改),因此手动增加了一个motd文件/run/motd.new

root@onecloud:~# cat /run/motd.new
This is a banner

测试是可以使用的。

补充:motd=/run/motd.dynamic文件是可以被/etc/updated-motd.d/目录中的脚本文件自动修改的。但是需要保证对这些文件有可执行权限。

root@onecloud:~# ls -lh /etc/update-motd.d/
total 32K
-rwxr-xr-x 1 root root 2.5K Feb  2  2023 10-armbian-header
-rwxr-xr-x 1 root root 6.6K Feb  2  2023 30-armbian-sysinfo
-rwxr-xr-x 1 root root 1019 Feb  2  2023 35-armbian-tips
-rwxr-xr-x 1 root root 1.3K Feb  2  2023 40-armbian-updates
-rwxr-xr-x 1 root root  895 Feb  2  2023 41-armbian-config
-rwxr-xr-x 1 root root  554 Feb  2  2023 98-armbian-autoreboot-warn
-rwxr-xr-x 1 root root  451 Jun 23 06:47 quotes.txt
root@onecloud:~#
root@onecloud:~# run-parts /etc/update-motd.d/
  ___              ____ _                 _
 / _ \ _ __   ___ / ___| | ___  _   _  __| |
| | | | '_ \ / _ \ |   | |/ _ \| | | |/ _` |
| |_| | | | |  __/ |___| | (_) | |_| | (_| |
 \___/|_| |_|\___|\____|_|\___/ \__,_|\__,_|

Welcome to Armbian 23.02.0-trunk Jammy with Linux 6.1.9-meson

No end-user support: built from trunk

System load:   6%               Up time:       8 days 22:32
Memory usage:  45% of 990M      Zram usage:    47% of 495M      IP:            172.18.0.1 172.17.0.1 10.0.0.5
CPU temp:      49°C             Usage of /:    48% of 6.9G

Tip of the day: What is new in Armbain 24.5 Havier https://www.armbian.com/newsflash/armbian-24-5-1-havier/

[ 73 security updates available, 131 updates total: apt upgrade ]
Last check: 2024-06-24 00:00

参考链接:https://manpages.ubuntu.com/manpages/bionic/man5/update-motd.5.html

https://manpages.ubuntu.com/manpages/bionic/man8/pam_motd.8.html


评论