Search code examples
bashsshsshpass

How to save ssh login welcome banner and disconnect


I'd like to be able to sign into an ssh terminal and save the banner information, and immediately disconnect. For example i can ssh into my terminal with:

sshpass -p[PASSWORD] ssh -p 2201 [USER_NAME]@ipaddress

I get the following login welcome banner:

Linux 2.6.21 #1 PREEMPT Tue Feb 1 16:12:56 CST 2011
Site ID: xml
Last login: Wed Aug  3 09:25:29 2016 from 156.98.4.11

I can pipe the "last login" information with

sshpass -p[PASSWORD] ssh -p 2201 [USER_NAME]@ipaddress > lastlogin.txt

However, this doesn't save the rest of the banner and I still have to hit ctrl+d to disconnect. Any help would be appreciated.


Solution

  • Nemanjas command is great, but be aware that the login banner isn't always located in the same file. On Ubuntu systems it's located in /etc/issue.net. The safest way would be to read the /etc/ssh/sshd_config file, where the Banner attribute is set.

    grep Banner < /etc/ssh/sshd_config | cut -d' ' -f 2
    

    Use this command to extract the file name.