email alert on root login in centos

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`" user@example.com


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??
udayrathorAsked:
Who is Participating?
 
jhheiderCommented:
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.
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
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.
0
 
udayrathorAuthor Commented:
yes even after ls -a id not showing

.  ..  .bash_history  .bash_profile  .custombuild  .rnd  setup.sh  .ssh
0
 
Sikhumbuzo NtsadaSenior IT TechnicianCommented:
..Okay, I'm not infront of Centos machine now, it will be difficult to check.

Also see "/etc/bashrc"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.