Sorry if this issue has been brought up before (I couldn't find it if it was) but mosh doesn't appear to show the message of the day (/etc/motd) when starting. Is there some way to enable this, either server-side or client-side?
One way is just to have the /etc/profile on the system run "cat /etc/motd".
Please reopen if this doesn't meet your needs.
This workaround would cause people using other login mechanisms to get a double motd. Given that even venerable servers such as OpenSSH consider this an important feature to have carried, I don't think mosh should ignore this. It might be low priority, but it should stay as an open issue. To win the hearts of system administrators, mosh needs to act as a reasonably "complete" solution, and not require tons of mosh-specific workarounds and hacks.
The reason this is tricky is that we are just executing a login shell on the remote machine. Whatever the login shell prints, we will display.
If OpenSSH has a standard list of things it prints before it runs the login shell, I guess we can certainly mimic that -- do you know where this list is?
You can also solve this with wrapper scripts; e.g. by replacing mosh-server with a script that does something like this:
if ( not grep { $_ eq "--" } @ARGV ) {
push @ARGV, '--', q{mosh-session};
}
exec { $SERVER } 'mosh-server.real', @ARGV;
And then mosh-session is a script that cat /etc/motd and then runs the user's login shell:
my $shell = (getpwuid( $> ))[ 8 ];
exec {$shell} "-$shell";
In session.c there is a function do_login that calls do_motd (which seems to just print /etc/motd) and display_loginmsg; the latter function is what handles the "Last login:" message that OpenSSH prints: I am not certain that that is considered "part of Unix" or is a random feature of OpenSSH, however (example: if you use telnet or rlogin, do you get that same login message prompt? if not, I'd say that isn't in the same category as motd, which you will get in those situations).
Fair enough, we can make mosh-server mimic this.
If you add this, you should also respect whether ~/.hushlogin exists to disable printing of the motd.
For reference, the OpenSSH check for ~/.hushlogin is in check_quietlogin of session.c, which is checked directly before the calls to display_loginmsg and do_motd at the end of do_login.
For the record, this doesn't work in Ubuntu 16.04.1 LTS. MOTD is stored in /etc/update-motd.d, and IIRC there's a PAM module that runs the MOTD (a la run-parts /etc/update-motd.d).
I can confirm the MOTD doesn't work on Ubuntu 16.04.1 LTS. But if you create manually a file /etc/motd the works.
@mcginty I found this page: https://www.devinhoward.ca/ideas/2015/nov/make-mosh-print-message-day-ubuntu-1404 which has a interesting workaround:
sudo ln -s /var/run/motd.dynamic /etc/motd
And all works great.
Now I'm trying to do MOTD work with Byobu. :)
@mhalano 's work around brings back up the problem of having it print twice when you use a different login method.
I recently added code to Mosh to print both /etc/motd and /var/run/motd.dynamic, which will also print twice with @mhalano's slightly hackish workaround. That's available in version 1.3.2 and later.
I tested now (better late than never, ugh?) on a fresh machine with Ubuntu 17.10, I connecte from the same machine and from other machine and and both work like a charm.
Most helpful comment
I recently added code to Mosh to print both
/etc/motdand/var/run/motd.dynamic, which will also print twice with @mhalano's slightly hackish workaround. That's available in version 1.3.2 and later.