When logging into a server via SSH (Secure Shell), you might want to display additional information, such as your Linux distribution (distro) details, right after the Message of the Day (MOTD). This can be quite useful for system administrators or users who need to quickly identify the operating system version they are working on.
Here, we will walk you through how to achieve this and provide you with a working example.
Problem Scenario
Original Code:
# This code will display the Linux distribution information after the MOTD
cat /etc/*release
While this command will show the distribution details, it does not automatically execute after the MOTD upon logging in via SSH.
Solution: Displaying Distro Information After MOTD
To display the distro information immediately following the MOTD during SSH login, you can modify the SSH configuration files to execute the desired command. Follow these steps:
Step 1: Edit the .bashrc
file
-
Open your terminal and connect to your server via SSH.
-
Once logged in, edit the
.bashrc
file located in your home directory. This file is executed for interactive non-login shells. Use a text editor likenano
orvim
:nano ~/.bashrc
-
Add the following line at the end of the file:
cat /etc/*release
-
Save and exit the editor (for
nano
, pressCTRL + X
, thenY
, andEnter
).
Step 2: Refresh the Terminal Session
To see the changes take effect without logging out, you can source the .bashrc
file:
source ~/.bashrc
Step 3: Test the Configuration
Now, if you log out and log back in via SSH, you should see the MOTD followed by the distribution information of your Linux server.
Additional Information
The command cat /etc/*release
combines the contents of any file that matches the *release
pattern, which typically includes files such as os-release
or lsb-release
, providing important details about your operating system, such as:
- Distro name
- Version number
- Codename
- Architecture
Practical Example
For instance, if you are using an Ubuntu server, the output might look like this after logging in:
Welcome to Ubuntu 20.04.3 LTS (Focal Fossa)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
No mail.
Last login: Tue Oct 26 10:00:00 2023 from 192.168.1.2
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
...
This allows you to quickly verify which version of Linux you are running immediately upon connecting to your server.
Conclusion
Displaying the distro information right after the MOTD at SSH login enhances your ability to quickly ascertain system information, which can be especially important in environments with multiple servers.
Useful Resources
By following the steps outlined above, you can easily customize your SSH login to show vital information for efficient system management.