Gentoo Archives: gentoo-user

From: Joshua Murphy <poisonbl@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] How send mail when user login on ssh or local ?
Date: Thu, 30 Jul 2009 17:49:36
Message-Id: c30988c30907301049i692dec95obde74a0c8aed8b9c@mail.gmail.com
In Reply to: [gentoo-user] How send mail when user login on ssh or local ? by Vagner Rodrigues
1 2009/7/30 Vagner Rodrigues <vagner@×××××××××××.org>:
2 >
3 >
4 > Hi Folks !
5 >
6 >
7 >  Somebody  know how I to  so send mail with  IP and Date/time  when same
8 > user login on shell  ( remote or local ) ?
9 >
10 > I work with another admin's  and I never told me  when they access and
11 > for what  my server  to do something,  I try log but this can be erased
12 > and maybe mail can help me about access and with this I can Ask about
13 > this access.
14 >
15 >
16 >
17 >
18 >
19 >
20 >
21 > --
22 >
23 > Esta mensagem foi verificada pelo sistema de antivírus e
24 >  acredita-se estar livre de perigo.
25
26 Well, all questions regarding the reasons you'd be giving root privs
27 to someone you don't entirely trust aside... the quick and dirty
28 approach I can think of would be to modify the system wide
29 /etc/profile to check uid and send an email if a given uid is logged
30 in. In the end, there's little to no way I'm aware of to guarantee
31 being alerted about use once someone's being handed root privileges.
32
33 If you do go about setting it up that way... OpenSSH sets variables[1]
34 regarding the session (IP and such) and those can be used to identify
35 that. The `tty` command[2] can be used to tell you whether the access
36 is direct physical access to the system's virtual consoles or not. You
37 could even bypass dependency on the local system having working mail
38 configuration and such if you have an smtp server off-host you can
39 send through by using netcat. A Windows variation[3] I found of the
40 same principle idea does just that. And, lastly, if you use sudo you
41 can leverage its own auditing capabilities to know when it's being
42 used[4].
43
44
45 [1] For example:
46 SSH_CLIENT=127.0.0.1 44681 22
47 SSH_TTY=/dev/pts/1
48 SSH_CONNECTION=127.0.0.1 44681 127.0.0.1 22
49 Which are of the form:
50 SSH_CLIENT=<client ip> <client port> <server port>
51 SSH_TTY=<local tty or pty>
52 SSH_CONNECTION=<client ip> <client port> <server ip> <server port>
53
54 [2] http://swoolley.org/man.cgi/tty
55
56 [3] http://community.spiceworks.com/how_to/show/225
57
58 [4] http://www.cyberciti.biz/faq/sudo-send-e-mail-sudo-log-file/
59
60 --
61 Poison [BLX]
62 Joshua M. Murphy
63 "Real programmers can write assembly code in any language." - Larry Wall