Every time I ssh into my server the server prints the last login date and time. But I don't like the format. For ex:

Last login: Sun Jan 31 12:12:13 2016 from

I want to to disable the message (in the config) and instead change it's location to the motd (00-header). How can I do it? Example how it should look:

Last login: 2016-01-31 12:12:13 from

1 Answer 1


As shown in the related question on serverfault , How do I edit the SSH “last login” message? , the line itself is built into the /usr/sbin/sshd binary. Thus to edit it it would be necessary to edit source code and recompile it yourself, which is somewhat more of a bother and more work than necessary

Confirming the results found on serverfault question

skolodya@ubuntu:$ file /usr/sbin/sshd                                          
/usr/sbin/sshd: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=b0aaeed8d674586459d21eb2d548a848c33de3a9, stripped

skolodya@ubuntu:$ strings /usr/sbin/sshd | grep -i "last login"                
Last login: %s
Last login: %s from %s

You can however tell sshd not to print message of the day and the last login (as per this answer )

Open the file /etc/ssh/sshd_config with any editor, make sure if you use command line editor you use sudo and if GUI editor - gksu, for instance

  sudo vi /etc/ssh/sshd_config

Append the following lines

PrintMotd no
PrintLastLog no

You can place the following function into your $HOME/.bashrc file at the top

function ssh_login_date
 if [ ! -z "$SSH_CLIENT" ]; then
   printf "Last login %s from %s \n" "$( date +%F" "%H":"%M":"%S  )" "$(echo $SSH_CLIENT|  awk '{print $1}' )"

And call the function at the end of the file

  • Oops, I did not mention that I wanted to disable the message and integrate it into the motd. So sorry. I updated my question to reflect what I actually wish to accomplish.
    – Avamander
    Feb 1, 2016 at 15:21
  • 1
    See my edit please Feb 1, 2016 at 15:36
  • Could you also please tell how to use grep plus any other command to print the last login time just as the example in my question?
    – Avamander
    Feb 1, 2016 at 15:39
  • 1
    Well . . .it's possible to grep last login, but that's not the issue. Simplest way would be to add modified date command to your .bashrc. The problem is that this shows time at the time of login to the ssh session, not the time last physical login was made, because it sshd ignores tty logins as far as I can see. I'm gonna make another edit, but that's as far as I can help Feb 1, 2016 at 16:01
  • Edit done, please see it Feb 1, 2016 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.