修改SSH欢迎消息以包含系统IP地址

我有几次我无法记住给定系统的IP地址,但当时能够使用主机名进行连接。 作为一个例子,刚才我想在我的路由器上设置端口转发,并且不记得目标系统的IP。

我想知道是否可以将系统的IP地址添加到SSH连接上显示的欢迎消息中。

我想要修改的默认欢迎消息,如果该术语含糊不清,则是“

Linux [hostname] 2.6.35-32-generic #64-Ubuntu SMP Tue Jan 3 00:47:07 UTC 2012 x86_64 GNU/Linux Ubuntu 10.10 Welcome to Ubuntu! * Documentation: https://help.ubuntu.com/ 

在那里的某个地方,我想我想添加刚刚登录的系统的IP地址。 有什么建议? 除了交换我的大脑以获得更多RAM的新型号?

您提到的消息是“motd”或“每日消息”。 它包含在/etc/motd

这是由update-motd生成的,其文档位于: https : //wiki.ubuntu.com/UpdateMotd#Design

请参阅此相关问题: 如何编辑ssh motd?

要直接回答您的问题,您可以使用以下内容添加名为/etc/update-motd.d/50-ip-address的文件:

 #!/bin/bash ifconfig |grep "inet addr" 

这将非常简单地将系统上所有已配置的Internet地址添加到motd文件中。

motd在“每次登录时” man update-motd (根据man update-motd )。 您可以使用该号码作为脚本名称的第一部分来决定IP地址的显示顺序。

由于/etc/update-motd.d中的文件只是shell脚本,因此您可以根据需要编写简单或复杂的内容。

这可能比您想要/需要的更多,但是landscape-common软件包会自动将系统信息(包括IP地址)添加到MOTD。

 Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-28-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Tue Jul 12 10:21:51 MDT 2016 System load: 0.09 Users logged in: 1 Usage of /: 12.3% of 225.17GB IP address for enp7s0: 192.168.X.XXX Memory usage: 45% IP address for wlp9s1: 192.168.X.XXX Swap usage: 0% IP address for docker0: 172.17.0.1 Processes: 397 Graph this data and manage this system at: https://landscape.canonical.com/ 0 packages can be updated. 0 updates are security updates. Last login: Tue Jul 12 10:03:16 2016 from 192.168.X.XXX 

具体来说,它在/etc/update-motd.d/目录中的/usr/share/landscape/landscape-sysinfo.wrapper中添加了一个符号链接。