email alert on root login in centos

Posted on 2012-09-10
Last Modified: 2012-10-19
i want to setup email alert on ssh root login
i read few forum about this

vi .bash_profile
Scroll down to the end of the file and add the following line:

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

but it not working then few people suggest that .bashrc is the file in which i need to add the line
but in my centos root directory no file .bashrc

how can i get the email alert??
Question by:udayrathor
    LVL 17

    Expert Comment

    by:Sikhumbuzo Ntsada
    Even if you do an "ls -a" you still cannot see it?

    can you go ahead and type "vi .bashrc"
    It's hidden, it should be there.

    Author Comment

    yes even after ls -a id not showing

    .  ..  .bash_history  .bash_profile  .custombuild  .rnd  .ssh
    LVL 17

    Expert Comment

    by:Sikhumbuzo Ntsada
    ..Okay, I'm not infront of Centos machine now, it will be difficult to check.

    Also see "/etc/bashrc"
    LVL 3

    Accepted Solution

    If /root/.bashrc doesn't exist, creating one is trivial. Just edit or create the file (such as via vi /root/.bashrc) and it should be executed on login, unless you're configured to prevent it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now