Giving yourself a quieter SSH login

Posted by Steve on Fri 24 Aug 2007 at 15:13

Tags: , ,

Usually when you connect to a server remotely, via ssh, you'll be shown the "message of the day", the last time you logged in to the machine, and other details. Here's a simple way to disable that behaviour.

By default the display of the message of the day is read from the file /etc/motd - this is usually configured to happen by PAM, via a line such as this in /etc/pam.d/ssh & /etc/pam.d/login:

# Prints the motd upon succesful login
session    optional   pam_motd.so

The obvious way to disable this behaviour is to remove this from the relevant PAM file(s). However doing this will remove the behaviour from all users of the machine - which might not be appreciated.

Instead we're going to look at the file /etc/login.defs - this file contains various settings which are used by different login programs.

By default you should see this:

#
# If defined, file which inhibits all the usual chatter during the login
# sequence.  If a full pathname, then hushed mode will be enabled if the
# user's name or shell are found in the file.  If not a full pathname, then
# hushed mode will be enabled if the file exists in the user's home directory.
#
HUSHLOGIN_FILE  .hushlogin
#HUSHLOGIN_FILE /etc/hushlogins

This is our solution. If you want to have a "quiet" login then you may run this:

skx@vain:~$touch ~/.hushlogin

To show the difference in behaviours here's an example of before and after (note that I'm using SSH keys here, so there is no password prompt):

Before creating .hushlogin

skx@vain:~$ssh localhost
Linux steve 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Aug 24 09:38:52 2007 from localhost.localdomain
skx@vain:~$

After creating .hushlogin

skx@vain:~$ssh localhost
skx@vain:~$

The downside to this solution is that you might miss a message saying something like this:

Last login: Wed Aug 22 16:00:10 2007 from l33t.hax0r.some.ips

(I did once detect that an account of mine had been compromised when I noticed the previous login location was utterly unlikely to have been mine ..)


Posted by cparker (204.136.xx.xx) on Fri 24 Aug 2007 at 15:56
[ Send Message | View cparker's Scratchpad | View Weblogs ]
What I'd actually like to be able to do is have the MOTD automatically change itself on a daily (or perhaps even per-login) basis based on the contents of a quotes file. I've been thinking of writing a fortune cookie script that would output a random fortune to the MOTD, but I'd like a seamless way to do this, possibly by changing the MOTD functionality to accept output from a script instead of just reading a file. Is this possible (without changing/recompiling source code)?

[ Parent | Reply to this comment ]

Posted by Anonymous (84.20.xx.xx) on Fri 24 Aug 2007 at 16:01
You can run 'fortune' from cron and output it to motd?

[ Parent | Reply to this comment ]

Posted by Steve (80.68.xx.xx) on Fri 24 Aug 2007 at 16:17
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Run this:

cp /etc/motd /etc/motd.header

Then create /etc/cron.hourly/motd with something like this in it:

#!/bin/sh
cp /etc/motd.header /etc/motd
/usr/games/fortune >> /etc/motd

That should do the job ..

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (88.109.xx.xx) on Sat 25 Aug 2007 at 03:01
better to do:

#!/bin/sh
cp /etc/motd.header /etc/motd.new
/usr/games/fortune >> /etc/motd.new
mv /etc/motd.new/etc/motd
#EOF

this way there the new motd file is put in place atomically so three is no race condition.

(yes I'm bored!)

Anon

[ Parent | Reply to this comment ]

Posted by Anonymous (90.184.xx.xx) on Sat 25 Aug 2007 at 13:08
Got your point. But one might argue that race conditions are very rare in this environment.

Unless, of course, /usr/games/fortune executes for more than an hour ... ;-)

(This is Saturday -- I'm bored too)

-Martin

[ Parent | Reply to this comment ]

Posted by Anonymous (87.210.xx.xx) on Mon 10 Sep 2007 at 07:27
Forgive me my ignorance, for I am only a beginner...
But where exactly is the (theoretical?) race condition in the first script, and how does the second script solve this?

Thanks!
-Lucas

[ Parent | Reply to this comment ]

Posted by Anonymous (59.167.xx.xx) on Tue 25 Sep 2007 at 15:26
Also a bit of a newbie, but isn't there now the exact same race condition for /etc/motd.new as there was for /etc/motd in the first one?

[ Parent | Reply to this comment ]

Posted by Anonymous (152.43.xx.xx) on Wed 3 Oct 2007 at 22:03
Yes, but it doesn't matter; the login process reads /etc/motd, not /etc/motd.new. So while it would be possible (but extremely unlikely) to send a half-written /etc/motd to the client, with the mv you'd either send the old motd, or the new one.

[ Parent | Reply to this comment ]

Posted by Dainichi (80.68.xx.xx) on Mon 27 Aug 2007 at 12:48
[ Send Message ]

If you want to run only few commands remotely, you can just type
#ssh user@host bash
In this case, no virtual terminal will be created, so, "w" command will not disclosure you.

[ Parent | Reply to this comment ]

Posted by Anonymous (62.89.xx.xx) on Mon 27 Aug 2007 at 15:04
To hide the message of the day there is an ssh-server option

simply

PrintMotd no

in /etc/ssh/sshd_config

polarizers 2 cents

[ Parent | Reply to this comment ]

Posted by Anonymous (59.167.xx.xx) on Tue 25 Sep 2007 at 15:28
But won't that turn off the motd for all users, rather than just the desired user?

[ Parent | Reply to this comment ]

Posted by svanstrom (83.253.xx.xx) on Thu 30 Aug 2007 at 12:58
[ Send Message ]
Have a look at these, and then add something suitable to .login (or whatever you're using):

man faillog
man last
man lastb
man lastlog

man chklastlog
(Part of chkrootkit.)

[ Parent | Reply to this comment ]

Posted by rodross (74.235.xx.xx) on Fri 7 Sep 2007 at 07:52
[ Send Message ]
The implementation of various login messages I know is a feature available in NetBSD standard via ssh. I tend to use quieter clients and servers for ssh on all my debian machines. Dropbear is really nice on my smaller devices and lsh works really well for me. Great ideas above for MOTD. I tend to limit access with filters so the chances of even me logging in remotely is remote, unless the machine is on the allow list so no remote keys though I know it would make it more simple. I wonder what would happen if you enforced password aging, what kind of MOTD would you get when time ran out ?
Cheers,
Rod Ross

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search