Customized My_Linux-Lab Motd

1.Before Login

1. change the sudor file, so that it will not prompt double login

              sudo visudo

    change it to:

              username ALL=(ALL) NOPASSWD: /usr/local/bin/neofetch

    :wq

2.sudo vim /etc/profile.d/neofetch.sh

     change it to:

                #!/bin/bash

                 neofetch > /etc/issue                                                             

 

3. You need to make sure the script is executable:

       sudo chmod +x /etc/profile.d/neofetch.sh

 

4. Update permissions of /etc/issue (not recommended)

If you want to avoid using sudo in the script, you could change the permissions of /etc/issue temporarily. However, this is not recommended because modifying permissions for sensitive system files can create security risks.

   To do so, you would run:

              sudo chmod 666 /etc/issue


                                        2.After Login

Auto-Update /etc/motd for All Users

If you want to dynamically update /etc/motd (which is shown for every user who logs in), follow these steps:

Step 1: Create the Script

sudo vim /etc/profile.d/update-motd.sh

Step 2: Add the Script

Add the following content to include username, hostname, and IP address:

#!/bin/bash

# Generate a new MOTD dynamically for all users

echo "=====================================" | sudo tee /etc/motd > /dev/null

echo " Welcome $(whoami) to $(hostname)" | sudo tee -a /etc/motd > /dev/null

echo "=====================================" | sudo tee -a /etc/motd > /dev/null

echo "Username : $(whoami)" | sudo tee -a /etc/motd > /dev/null

echo "Hostname : $(hostname)" | sudo tee -a /etc/motd > /dev/null

echo "IP Address: $(hostname -I | awk '{print $1}')" | sudo tee -a /etc/motd > /dev/null

echo "=====================================" | sudo tee -a /etc/motd > /dev/null


Step 3: Give Execute Permissions

Make the script executable:

sudo chmod +x /etc/profile.d/update-motd.sh

This script will dynamically update /etc/motd with username, hostname, and IP address every time a user logs in.

Using Oh-My-Bash (Zsh-like Prompt in Bash)

Oh-My-Bash is a framework that provides pre-configured themes for a stylish Bash prompt.


Install Oh-My-Bash

bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"


Change to a Custom Theme

  1. Edit .bashrc:

vim ~/.bashrc

  1. Look for the line:

OSH_THEME="font"

Change it to a theme like:

OSH_THEME="pure"

  1. Apply changes:

source ~/.bashrc


Note:

    How to Remove the “Welcome to Ubuntu” Terminal Login Message

    That banner is controlled by the /etc/update-motd.d/ system, which dynamically builds the Message     of the Day (MOTD) shown at login.

    Step-by-Step: Disable Terminal Login Banner

  1. Open a terminal.
  2. Make all MOTD scripts non-executable:

                        sudo chmod -x /etc/update-motd.d/*

Comments

Popular posts from this blog

Install Moodle 4.3 on Ubuntu 23.10

Activate window and MS-Office with PowerShell

GNS3 installation in Linux