Can I disable SSH last-login and MOTD on a per-user basis?

8

3

I'm aware you can disable last-login and message-of-the-day messages when starting SSH sessions by having PrintLastLog no and PrintMotd no in /etc/ssh/sshd_config.

However, I don't have permission to modify /etc/ssh/sshd_config in the system I'm accessing. Is there a way to set PrintLastLog no and PrintMotd no for my local user only?

Alexander - Reinstate Monica

Posted 2014-01-21T00:08:58.260

Reputation: 283

Answers

10

Yes you can, add the Match User directive to your sshd_config file like so:

Match User root 
    PrintlastLog no
    PrintMotd no

The Match directive also works for Group and Address to match for GEOS/Unix group and IP Address retrospectively.

Update:

As a per user basis without access to the sshd_config then you would just create an empty file in $HOME/.hushlogin which would prevent bash in interactive mode to output these alerts. This also works under other systems that use login(1) such as telnet and screen sessions.

Update 2:

To surpress the Banner output from sshd on a per session basis use ssh -q <host>or include LogLevel quiet in your ~/.ssh/config

Dwight Spencer

Posted 2014-01-21T00:08:58.260

Reputation: 366

OP said he cannot modify /etc/ssh/sshd_config – MariusMatutiae – 2014-01-21T08:48:49.777

Thanks @MariusMatutiae for pointing that out. I've updated my answer to account for that. – Dwight Spencer – 2014-01-21T23:50:40.870

4~/.hushlogin suppressed the motd and last login messages. :D Bonus points if you can disable the banner as defined by Banner /etc/issue in /etc/ssh/sshd_config. – Alexander - Reinstate Monica – 2014-01-22T15:19:38.257

1Thanks @XAleXOwnZX I completely forgot about that. I've updated the answer to include the Banner suppression. – Dwight Spencer – 2014-01-22T23:07:52.730

2

Not all OpenSSH implementations as those in Ubuntu allow PrintMotd or PrintlastLog in Match User section.

One may find this askubuntu question usefull with some workaround if s/he got error like:

/etc/ssh/sshd_config line 97: Directive 'PrintMotd' is not allowed within a Match block

Rostislav Kandilarov

Posted 2014-01-21T00:08:58.260

Reputation: 121