Search code examples
pythonsshparamiko

How to get SSH message of the day (MOTD) using python's paramiko?


Couldn't find a way to get MOTD (/etc/motd file) after successful login. I use Paramiko but doing so with any other Python library would be great

Thanks in advance for any help


Solution

  • /etc/motd file is printed on an interactive terminal. As such there's no nice API to retrieve it from a non-interactive program.

    Probably the only way is to open an interactive shell session using SSHClient.invoke_shell and read its output.

    Instead, consider simply reading/downloading the /etc/motd file via SFTP (SFTPClient class).