Ubuntu Server welcome message

Ubuntu Server Welcome Message

recently I use the raspberry pi 4 to build personal webiste server, use unbuntu server as the OS.

Becuase the ubuntu server only use the CLI, so I use ssh to login, and here is the first thing I met: the welcome message, here is look like

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-1064-azure x86_64)

Documentation:  https://help.ubuntu.com
Management:     https://landscape.canonical.com
Support:        https://ubuntu.com/pro
System information as of Mon Jun  3 10:03:27 UTC 2024

System load:  0.16               Processes:             127
Usage of /:   22.6% of 28.89GB   Users logged in:       0
Memory usage: 20%                IPv4 address for eth0: 10.0.2.4
Swap usage:   0%


Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

2 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Last login: Fri May 31 07:41:57 2024 from 10.0.1.4

but I don’t like this, so I want to change it, change ssh login message.

Here I find a website can personalize somethign message: [Text to ASCII Art Generator (TAAG) (patorjk.com)](https://patorjk.com/software/taag/#p=display&h=0&v=0&f=ANSI Shadow&t=Berry Node )

and my message is that:

██████╗ ███████╗██████╗ ██████╗ ██╗   ██╗    ███╗   ██╗ ██████╗ ██████╗ ███████╗
██╔══██╗██╔════╝██╔══██╗██╔══██╗╚██╗ ██╔╝    ████╗  ██║██╔═══██╗██╔══██╗██╔════╝
██████╔╝█████╗  ██████╔╝██████╔╝ ╚████╔╝     ██╔██╗ ██║██║   ██║██║  ██║█████╗  
██╔══██╗██╔══╝  ██╔══██╗██╔══██╗  ╚██╔╝      ██║╚██╗██║██║   ██║██║  ██║██╔══╝  
██████╔╝███████╗██║  ██║██║  ██║   ██║       ██║ ╚████║╚██████╔╝██████╔╝███████╗
╚═════╝ ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝       ╚═╝  ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝

and then we need to delete something and add the personalize message, before we delete it, we need to know what is the structure of the message

The structure of the welcome message

The welcome message after logging into an Ubuntu server via SSH is typically generated by a combination of scripts and text files that are executed or displayed when a user logs in. These can include the Message of the Day (MOTD), SSH Banner.

Message of the Day (MOTD)

The static part of the MOTD is stored in /etc/motd. However, Ubuntu often uses dynamic MOTD generation scripts instead of this static file.

  • Static MOTD: If you want to use a static MOTD, simply edit the /etc/motd file . If the file doesn’t exist, you can create it.

  • Dynamic MOTD: Ubuntu uses scripts in /etc/update-motd.d/ to dynamically generate the MOTD. Each script in this directory contributes to the final MOTD displayed to the user.

    • To modify existing messages, edit the scripts in /etc/update-motd.d/.

    • To add new messages, create a new script in /etc/update-motd.d/. Scripts are executed in alphanumeric order, so prefix your script’s name with a number to control its order in the MOTD:

      echo -e '#!/bin/sh\necho "Your custom message here"' | sudo tee /etc/update-motd.d/99-custom-message
      sudo chmod +x /etc/update-motd.d/99-custom-message
      

SSH Banner

The SSH banner is another way to display messages upon login. It’s defined in the SSH daemon configuration.

  • To set up an SSH banner, first create a text file with your desired message:

    sudo nano /etc/ssh_banner
    

    Add your message to this file and save it.

  • Next, edit the SSH daemon configuration file to use this banner:

    sudo nano /etc/ssh/sshd_config
    

    Add or modify the line:

    Banner /etc/ssh_banner
    
  • Finally, restart the SSH service for changes to take effect:

    sudo systemctl restart sshd
    

The display order of the messages

SSH Banner(displayed before the login process completes) --> Dynamic Motd --> Static Motd

The scripts in the /etc/update-motd.d

Here is an example of /etc/update-motd.d directory files.

plain@BerryNode:/etc/update-motd.d$ ls -all
total 56
drwxr-xr-x  2 root root 4096 May  9 00:53 .
drwxr-xr-x 98 root root 4096 May 10 06:19 ..
-rwxr-xr-x  1 root root 1220 Oct 15  2021 00-header
-rwxr-xr-x  1 root root 1151 Jan  2 22:57 10-help-text
lrwxrwxrwx  1 root root   46 May  9 00:53 50-landscape-sysinfo -> /usr/share/landscape/landscape-sysinfo.wrapper
-rwxr-xr-x  1 root root 5023 Oct 15  2021 50-motd-news
-rwxr-xr-x  1 root root  218 Feb 28  2023 90-updates-available
-rwxr-xr-x  1 root root  296 Nov  7  2023 91-contract-ua-esm-status
-rwxr-xr-x  1 root root  558 Jan 10  2023 91-release-upgrade
-rwxr-xr-x  1 root root  165 Feb 19  2021 92-unattended-upgrades
-rwxr-xr-x  1 root root  379 Feb 28  2023 95-hwe-eol
-rwxr-xr-x  1 root root  111 Aug 18  2020 97-overlayroot
-rwxr-xr-x  1 root root  142 Feb 28  2023 98-fsck-at-reboot
-rwxr-xr-x  1 root root  144 Feb 28  2023 98-reboot-required

These scripts can be customized, replaced, or disabled based on your preferences for what information should be displayed in the MOTD.

and here is what this file do

00-header && 10-help-text file

This 2 files is easy to understand what the meaning by its code.

50-landscape-sysinfo && 50-motd-news

The presence of two scripts starting with 50- in the /etc/update-motd.d/ directory and the specific behavior and output you’re seeing are due to how Ubuntu structures its dynamic Message of the Day (MOTD) system. Let’s address your questions one by one:

The function of this 2 files

50-landscape-sysinfo: This is a symbolic link to the Landscape system information wrapper. When executed, it displays various system information such as load, disk usage, memory usage, and more. Landscape is a system management tool provided by Canonical (Ubuntu’s parent company).

50-motd-news: This script is designed to fetch and display news from Ubuntu, which can include security notices, information on new versions, and other relevant news for Ubuntu users. It’s part of the motd-news service.

About the --> of the 50-landscape-sysinfo

The -> symbol indicates that 50-landscape-sysinfo is a symbolic link (symlink) rather than a regular file. A symlink is a type of file that points to another file or directory. In this case, 50-landscape-sysinfo points to /usr/share/landscape/landscape-sysinfo.wrapper. When the symlink is executed, it actually executes the file it points to.

  • This means that when the MOTD system reaches 50-landscape-sysinfo, it doesn’t run a script directly located at that path but instead runs /usr/share/landscape/landscape-sysinfo.wrapper.
  • The use of symlinks in this context allows for easier management and updates of scripts. For example, a package update can replace the target script without needing to modify the contents of /etc/update-motd.d/.

How to disable 50-motd-news

as we already know the 50-motd-news just shows the news or something like, so I decide to disable showing this file, as it’s message is not necessary to me.

To easily disable the execution of the 50-motd-news script without modifying its source code, we can leverage the mechanism hinted at in the script itself, particularly around line 36:

[ "$ENABLED" = "1" ] || exit 0

This line checks for an environment variable ENABLED. If ENABLED is not set to "1", the script exits immediately without doing anything. This mechanism is designed to allow easy enabling or disabling of the script through configuration rather than code changes.

90/91/92/95/97/98 file

  • 90-updates-available: Checks for package updates and displays the number of packages that can be updated, along with instructions on how to update them.

  • 91-contract-ua-esm-status: Displays information about the Ubuntu Advantage (UA) service and Extended Security Maintenance (ESM) status for the server. UA is a subscription service provided by Canonical that offers additional support and security updates.

  • 91-release-upgrade: Checks if a new release of Ubuntu is available for upgrade and provides information on how to upgrade.

  • 92-unattended-upgrades: Informs about automatic updates configuration status, indicating whether unattended upgrades (automatic security updates) are enabled or not.

  • 95-hwe-eol: If the system is using a Hardware Enablement (HWE) stack, this script warns the user when the HWE stack is nearing its end of life.

  • 97-overlayroot: Displays a message if the system is using overlayroot (a tool for making the root filesystem read-only). It’s useful for environments where you want to minimize writes to disk or protect the integrity of the system software.

  • 98-fsck-at-reboot: Indicates if a filesystem check (fsck) is scheduled for the next reboot. This can happen if there are detected inconsistencies in the filesystem.

  • 98-reboot-required: Notifies the user if a reboot is required, typically after certain updates or changes to critical system components.

The message of last login

and we can see last line of the welcome message, it look like: Last login: Mon May 13 00:23:19 2024 from ::1

It is not generated by any of the scripts in /etc/update-motd.d/. Instead, this message is produced by the SSH daemon (sshd) or the login program itself, depending on how you’re accessing the system.

and I think this message is vaulable, so I leave it.

login as: liupeng001 liupeng001@10.177.66.40's password: ┌──────────────────────────────────────────────────────────────────────┐ │ • MobaXterm Personal Edition v25.0 • │ │ (SSH client, X server and network tools) │ │ │ │ ⮞ SSH session to liupeng001@10.177.66.40 │ │ • Direct SSH : ✓ │ │ • SSH compression : ✓ │ │ • SSH-browser : ✓ │ │ • X11-forwarding : ✓ (remote display is forwarded through SSH) │ │ │ │ ⮞ For more info, ctrl+click on help or visit our website. │ └──────────────────────────────────────────────────────────────────────┘ Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-107-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sat Mar 22 04:11:52 PM CST 2025 System load: 0.0 Processes: 365 Usage of /: 10.4% of 1.83TB Users logged in: 1 Memory usage: 4% IPv4 address for docker0: 172.17.0.1 Swap usage: 0% IPv4 address for eno1: 10.177.66.40 Temperature: 46.0 C 2 devices have a firmware upgrade available. Run `fwupdmgr get-upgrades` for more information. Expanded Security Maintenance for Applications is not enabled. 0 updates can be applied immediately. Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status The list of available updates is more than a week old. To check for new updates run: sudo apt update 15 updates could not be installed
03-23
<think>好的,用户想通过MobaXterm SSH连接Ubuntu服务器后查看系统负载、内存使用率、磁盘空间等信息。首先,我需要回忆一下在Linux系统中常用的系统状态命令。 系统负载通常可以用uptime或者top命令查看,uptime会显示最近1、5、15分钟的平均负载。内存使用率的话,free -h命令比较合适,加上-h参数可以更易读。磁盘空间自然是用df -h,显示各分区的使用情况。 然后,用户可能还想知道其他相关信息,比如登录信息。这时候需要查看/var/log/auth.log或者使用last命令查看最近的登录记录。另外,系统运行时间可以用uptime或者直接看/proc/uptime的内容。 可能还需要提到一些综合工具,比如htop,它比top更直观,或者glances这样的工具,提供更全面的监控。不过用户可能没有安装这些,所以还是以基本命令为主。 还要注意用户使用MobaXterm,这是一个支持SSH的终端工具,执行命令后的输出应该和普通终端一样。需要确保命令的正确性和可执行性,比如是否需要sudo权限。例如查看auth.log可能需要sudo权限。 然后,根据引用内容,用户提供的参考中有提到磁盘阈值(DISK_THRESHOLD)和超时设置,可能在回答中提及磁盘报警阈值相关的内容,比如df显示的百分比是否超过阈值。 最后,生成相关问题需要考虑用户可能的后续疑问,比如如何持续监控、如何清理磁盘空间、如何查看特定用户的登录记录等等。这些都需要涵盖进去。</think>[逐步解答] 通过MobaXterm SSH连接Ubuntu服务器后,可以通过以下命令查看系统状态信息: 1. 系统负载查看 执行命令: ```bash uptime ``` 输出示例: ``` 15:32:01 up 2 days, 4:15, 1 user, load average: 0.08, 0.03, 0.05 ``` - 最后3个数值分别表示1分钟、5分钟、15分钟的平均负载[^3] - 单核CPU负载值超过1.0表示过载,多核CPU需乘以核心数计算阈值 2. 内存使用率 执行命令: ```bash free -h ``` 输出示例: ``` total used free shared buff/cache available Mem: 7.7G 2.1G 3.2G 89M 2.4G 5.2G Swap: 2.0G 0B 2.0G ``` - `available`列表示可用内存(包含缓冲/缓存) - 内存使用率计算公式:$$ \text{使用率} = \frac{used}{total} \times 100\% $$ 3. 磁盘空间检查 执行命令: ```bash df -h ``` 输出示例: ``` Filesystem Size Used Avail Use% Mounted on /dev/sda1 98G 24G 69G 26% / tmpfs 3.9G 0 3.9G 0% /dev/shm ``` - `Use%`列直接显示分区使用率 - 当使用率达到设置的$DISK\_THRESHOLD$(默认95%)时需及时清理 4. 登录信息查看 执行命令: ```bash last -n 10 ``` 输出示例: ``` user1 pts/0 192.168.1.100 Fri Jun 21 15:30 still logged in user2 pts/1 203.0.113.45 Fri Jun 21 14:55 - 15:20 (00:25) ``` - 显示最近10条登录记录 - 完整日志路径:$ /var/log/auth.log $[^1] 5. 综合监控(需安装) ```bash htop ``` 该命令提供交互式界面,整合显示: - CPU使用率 - 内存占用排行 - 进程资源消耗 - 温度监控等
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值