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.

  • 27
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值