LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-27-2013, 05:32 PM   #1
Mark382717
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Rep: Reputation: 0
Unhappy postfix setup to work with email script.


123

Last edited by Mark382717; 09-30-2013 at 08:23 PM.
 
Old 10-05-2013, 08:08 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator Response

Please do not edit content to remove the original content unless the changes correct the thread. Here at LQ we try to help everyone. New threads that are issues that may/will help you and other members are valuable to us at LQ. Please be patient for LQ members to respond thus hopefully helping you and other LQ members.

Original Post content with vbcode tags added for clarity;
Quote:
I have cobbled together a small script that emails my username when an SSH connection is made by one of the people who I have given access too (Script listed below). The script works great, but I'd like to have it email a non local email address rather than just the local user.

I did some reading and according to the articles I found made the following changes. The email just still just sits in mailq. Any help getting this working would be greatly appreciated. Thanks in advance.

1) Added these lines to
/etc/postfix/main.cf
--------------
Code:
relayhost = smtpserver.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
--------------
*smtpserver.com is a the smtp server for the hosting company where I have my domain hosted.

2) Added this line to
/etc/postfix/sasl_passwd
--------------
smtpserver.com:587 myemail@address.com : password
--------------


3) I then ran
--------------
postmap /etc/postfix/sasl_passwd
--------------

4) Then:
--------------
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem
--------------


5) Finally, I restarted postfix:
--------------
/etc/init.d/postfix reload
--------------



The email script is as follows and resides in
/etc/ssh/sshrc;
--------------
Code:
#!/bin/bash
# send email when any ssh login is successful
## set IP variable
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`

# email subject
SUBJECT="SSH login just occurred."

# Email To ?
EMAIL="user@host"

# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "  -- Alert -- "> $EMAILMESSAGE
echo "SSH Login was successful">> $EMAILMESSAGE
echo "User $USER just logged in from $ip">> $EMAILMESSAGE
echo `date`>> $EMAILMESSAGE
echo "  -- End alert --" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
# clear contents of tmp file
echo "Blank File"> $EMAILMESSAGE
--------------
Thread now reopened!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to setup an email server easily with the postfix and dovecot commands baronobeefdip Linux - Server 4 02-08-2013 12:35 AM
postfix and email setup claybv Linux - Software 2 04-08-2008 04:01 PM
EMail server setup: FC6+Postfix+Dovecot+Squirrelmail rdnewman Linux - Networking 5 08-04-2007 06:59 PM
setup multi domains email in postfix importboy03 Linux - Software 1 04-29-2003 04:06 PM
How to setup Postfix to send email via POP dwynter Linux - Software 2 07-02-2002 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration