PDA

View Full Version : How-To receive an email everytime someone logs in as root to your server


eWebtricity
08-21-2005, 05:27 PM
Contributed by Wythrol.

If you want to recieve an email everytime someone logs into your server using the root account you can use the following simple script in the root user profile.

Step 1:


[root@condor root]# cd /root/.ssh/


Step 2:


[root@condor .ssh]# ls -la
total 12
drwx------ 2 root root 4096 Nov 27 2004 .
drwxr-x--- 15 root root 4096 May 14 10:12 ..
-rw-r--r-- 1 root root 223 Nov 27 2004 known_hosts
[root@condor .ssh]# touch rc
[root@condor .ssh]# vi rc


Step 3:

Then cut and past this on a single line and change the parameters to suit your configuration


echo 'ALERT - Root Shell Access (yourserverhere) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" youremail@yourdomain.com (youremail@yourdomain.com)


Step 4:

Save the file and exit

That's it.

C-4 Hosting
08-21-2005, 08:28 PM
Contributed by Wythrol.

If you want to recieve an email everytime someone logs into your server using the root account you can use the following simple script in the root user profile.

Step 1:



Step 2:


[root@condor .ssh]# ls -la
total 12
drwx------ 2 root root 4096 Nov 27 2004 .
drwxr-x--- 15 root root 4096 May 14 10:12 ..
-rw-r--r-- 1 root root 223 Nov 27 2004 known_hosts
[root@condor .ssh]# touch rc
[root@condor .ssh]# vi rc


Step 3:

Then cut and past this on a single line and change the parameters to suit your configuration



Step 4:

Save the file and exit

That's it.


Is this Plesk or 1and1 Root Server specific??? Will this work with any dedicated Linux Server?

eWebtricity
08-22-2005, 11:50 AM
The general idea is the same and this should work on any *nix box, minus any adjustments for differences in the bsh, ksh, tsh or whatever shell you might be using.

shunter045
04-12-2006, 02:00 PM
there is no /root/.ssh/ folder on my fedora core 4 with plesk 8.0 server. any suggestions on how i can change the commands above to make it work?

eWebtricity
04-12-2006, 02:23 PM
You need to SSH to something else for the /root/.ssh folder to be created automatically or you could create it yourself manually. But just simply SSH'ing to something else will build it correctly for you.

shunter045
04-12-2006, 02:27 PM
I just SSH'd to my other 1and1server. It doesn't create the /.ssh/ folder. i'll try creating it and see if that works

shunter045
04-12-2006, 02:28 PM
nevermind.... i just ran plain "ls" and it didn't show up. "ls -la" lets it show :)

eWebtricity
04-12-2006, 02:29 PM
Interesting i just tested it on one of our new FC4 servers and it worked fine

Here's the permissions details if you need them


drwx------ 2 root root 4096 Apr 12 13:27 .ssh

dan.plifeye
05-13-2006, 06:10 AM
Is there a way to get emailed if and when any user logs in to SSH, not just the root?

eWebtricity
05-13-2006, 01:39 PM
I think you could edit the skeleton bashrc profile that gets applied to a new user when you add them, but I think that means you would also have to go back to the existing user profiles and edit their user profile to have it retroactive.

Highland might have a better answer on this one

nullensc
05-14-2006, 03:42 PM
Contributed by Wythrol.
If you want to recieve an email everytime someone logs into your server using the root account you can use the following simple script in the root user profile.

Work for me, thanks Wythrol and eWeb for sharing it.. :-)

Highland
05-16-2006, 12:03 PM
I poked around some to see if there was a solution for an entire server but I wasn't able to find one. Eash user has their own .ssh directory and I don't know of a way to automate creation of a file everytime you set up a new user. It might be possible to hack Plesk to do it but I'm leery of doing that just because of updates and such overwriting it.