Is there a way to display active SSH login details in the MOTD display? Like, I wanted to display the IP Address from where the connection got originated and how much time the session is active. Is this possible?

Additional Update:

# tty --silent && finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone   Host
root      root       pts/0          Jun 22 00:33                           (
root      root       pts/1          Jun 22 00:38                           (

Is there a way to remove Office & Office Phone from the above output so that it looks little more better? In addition, it just says at what time the user is logged in. Is there a way also to show how much time the user is logged in?


You could display the current users with who or finger. To run one of them on login, you could add it to the users' shell's startup files. Assuming your users run Bash (or some other shell that reads /etc/profile), you could put something like this there:

tty --silent && finger

(tty finds out if the shell is open on a terminal. Without testing it, the output could mess up noninteractive utilities.)

At least on Debian/Ubuntu, the default /etc/profile also runs scripts in /etc/profile.d/ (the files need to end with .sh), so you could put the command in a new file there, instead.

In addition, Ubuntu has a system specifically for updating the MOTD file dynamically. The pam_motd module runs scripts in /etc/update-motd.d and stores their output in /etc/motd.dynamic, which is then shown to the user. In this case, it goes through the usual MOTD process, so you don't need to check for tty or anything. See e.g. update-motd(5) and the UpdateMotd page on Ubuntu wiki.

  • Thank you for your answer. I have added some additional details in the question. Could you also help me with the same? Also, fedora based distribution doesn't come with finger tool installed and we will have to install it. is there any other alternate way so that we do not need to install any new utility.. Jun 21 '18 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.