Cool idea! I just tried it, and it works great. I added ESC [ 3 1 m before the text, and ESC [ 0 m afterwards, and now it is red.
In what context? I'm not sure I understand that question.
login() first prints a line that shows when you last logged in, and then prints the content of motd (much of this is configurable in login, this is the default configuration, I haven't messed with it). If your terminal emulator (could be the hardware console) can display ANSI colors, the color shows up. Here is an example of the output from my system (cut and paste from a terminal emulator on a Macintosh, so the color is gone):
Code:
ralphmac-wl_~ > ssh house.lr.los-gatos.ca.us
Last login: Wed Aug 2 07:19:38 2017 from ralphmac-wl.lr.los-gatos.ca.us
FreeBSD 11.1-RELEASE (GENERIC) #0 r321309: Fri Jul 21 04:10:47 UTC 2017
Host house.lr.los-gatos.ca.us
Unauthorized use of this computer is prohibited, and will be punished.
house_~ >
The line that says "Unauthorized use..." is now read. Here is a hex dump of my motd file:
Code:
00000000 46 72 65 65 42 53 44 20 31 31 2e 31 2d 52 45 4c |FreeBSD 11.1-REL|
00000010 45 41 53 45 20 28 47 45 4e 45 52 49 43 29 20 23 |EASE (GENERIC) #|
00000020 30 20 72 33 32 31 33 30 39 3a 20 46 72 69 20 4a |0 r321309: Fri J|
00000030 75 6c 20 32 31 20 30 34 3a 31 30 3a 34 37 20 55 |ul 21 04:10:47 U|
00000040 54 43 20 32 30 31 37 0a 48 6f 73 74 20 68 6f 75 |TC 2017.Host hou|
00000050 73 65 2e 6c 72 2e 6c 6f 73 2d 67 61 74 6f 73 2e |se.lr.los-gatos.|
00000060 63 61 2e 75 73 0a 0a 1b 5b 33 31 6d 55 6e 61 75 |ca.us...[31mUnau|
00000070 74 68 6f 72 69 7a 65 64 20 75 73 65 20 6f 66 20 |thorized use of |
00000080 74 68 69 73 20 63 6f 6d 70 75 74 65 72 20 69 73 |this computer is|
00000090 20 70 72 6f 68 69 62 69 74 65 64 2c 20 61 6e 64 | prohibited, and|
000000a0 20 77 69 6c 6c 20 62 65 20 70 75 6e 69 73 68 65 | will be punishe|
000000b0 64 2e 1b 5b 30 6d 0a |d..[0m.|
000000b7
Suggestion for debugging: Are you 100% sure that your terminal emulator can actually display colors? Try echo'ing in the shell: "ESC [ 3 1 m H a l l o ESC [ 0 m", and it should be red; if you use "3 4" in front, it should be blue. How you enter ESC depends on your shell; in both csh and bash it is Control-V Escape (using the escape key).
Warning: There is a motd service that lives in
/etc/rc.d/motd. If you enable it with "motd_enable=YES" in
/etc/rc.conf, then on every boot motd will be modified, but the modifications are minimal: It simply replaces the FreeBSD version in the first line with the up-to-date version.