SMTP Authentication (Postfix TLS SASL) on Ubuntu

posted on 22 Feb 2009 16:08 by jaiyuu in Linux

วันนี้มาติดตั้ง Mail Server ให้ใช้ SMTP Authentication ได้ ด้วย Postfix โดยที่ OS ที่ใช้ คือUbuntu นะครับ

More...

 

ไม่ขอพูดเรื่องการ install postfix ดีกว่า รู้สึกว่าสำหรับ ubuntu นั้นไม่ยากสำหรับทุกคนเพราะว่าเรามี apt-get นั่นเอง ส่วน postfix ที่ใช้นั้นเราต้อง support การทำงานร่วมกับ tls ด้วยนะครับ (แต่ที่ ubuntu ให้มามันก็ support อยู่แล้วนินา) ผ่านโลด
TLS on Postfix

 

เมื่อเรามี postfix อยู่ และ config เบื้องต้นเอาไว้แล้ว (หรือไม่ config อะไรเลย default มันก็ใช้ได้แล้ว) ลองดูเรื่อง TLS ครับ

 

smtpd_tls_cert_file=/etc/ssl/certs/mail-cert.pem
smtpd_tls_key_file=/etc/ssl/private/mail-key.pem
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache

 

ขอผ่านเรื่องการสร้าง SSL certificate ไปนะครับ ติ๊งต่างว่าเราทำกันไว้แล้ว หรือถ้ายังก็ไปหาลองทำกันเอานะครับ ลอง search หาคำว่า "openssl generate certificate" จะเจอเยอะแยะมากมายในการสร้าง self-signed certificates

เสร็จแล้วก็อย่าลืม restart postfix นะครับ

/etc/init.d/postfix restart

SMTP authentication with Postfix

เราต้องใช้ SASL ครับ มันคืออะไร ไว้จะมาอธิบายอีกทีครับ ตอนนี้ยังงงๆ ติดตั้งกันไปก่อนด้วย

apt-get install libsasl2 libsasl2-modules sasl2-bin

แล้ว apt-get ก็จัดให้ แล้วก็บอกส่งท้ายว่า

 

Setting up sasl2-bin (2.1.22.dfsg1-8ubuntu2) ...
* To enable saslauthd, edit /etc/default/saslauthd and set START=yes

 

เขาบอกว่าลงให้แล้วนะ แต่ยังไม่ได้ enable ถ้าจะใช้งานก็ให้ไปแก้ไฟล์ /etc/default/saslauthd ยังงี้ครับ

START=yes

ถ้าหาก postfix ของเรานั้นรันใน chroot environment (ก็ดีนะครับเพื่อความปลอดภัย) เราก็เอา sasl ของเรานั้น ไปทำงานใน directory ที่เราให้ postfix นั้นใช้ chroot ครับ ด้วยการเข้าไปแก้ parameter ของ การรัน sasld ในไฟล์ startup script คือ /etc/init.d/saslauthd ครับ ในส่วนของ DAEMON_ARGS=

DAEMON_ARGS="-m /var/spool/postfix/var/run/saslauthd"

แล้วอย่าลืมสร้าง directory ให้ sasl ของเรานะครับ

mkdir -p /var/spool/postfix/var/run/saslauthd

chown -R root.sasl /var/spool/postfix/var/run/saslauthd

เสร็จแล้วอย่าลืม restart saslauthd นะ

/etc/init.d/saslauthd restart

ลอง check ดูนะครับว่ามันรันได้ป่าว

ps -ef | grep saslauthd

Check ดูว่า sasl ได้สร้างไฟล์ หรือ socket ใน dir ที่ sasl ทำงานหรือเปล่า

ls -lh /var/spool/postfix/var/run/saslauthd

ในส่วนของ Postifx กันต่อครับ เราต้องสร้าง directory /etc/postfix/sasl และไฟล์ smtpd.conf ดังนี้

pwcheck_method: saslauthd

และ config เพิ่มเติมในไฟล์ /etc/postfix/main.cf ตามนี้ครับสำหรับ sasl

 

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_application_name = smtpd
broken_sasl_auth_clients = yes

 

 

smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
check_relay_domains

 

เสร็จแล้วก็ restart postfix โลด

/etc/init.d/postfix restart

ทดสอบครับด้วยการสร้าง string นี้จาก account และ password บนเครื่องของเราด้วยคำสั่ง

perl -MMIME::Base64 -e 'print encode_base64("usernameusernamepassword");'

มันก็จะได้ออกมาประมาณนี้นะครับ

dXNlcm5hbWUAdXNlcm5hbWUMb29iYXI=

แล้วก็ให้ copy string ชุดนี้เอาไว้นะครับเพื่อทดสอบด้วย telnet

telnet loclahost 25

มันจะออกมาประมาณนี้ครับ

 

220 mail.foo.com ESMTP Postfix
EHLO my.host
250-mail.foo.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-XVERP
250 8BITMIME
AUTH PLAIN dXNlcm5hbWUAdXNlcm5hbWUMb29iYXI=
235 Authentication successful
QUIT
221 Bye

 

เราก็ทักทาย smtp server ตามตัวอย่างครับ ตัวหนาด้านบนคือคำสั่งที่เราใส่เพื่อคุยกับ smtp ครับ ถ้าขึ้น successful ดังตัวอย่างแสดงว่าโอเคแล้ว อย่าลืมตรวจสอบ log file ดูเล่นๆครับ /var/log/mail.log ก็เสร็จครับ หรือลองกับ mail client อย่าง Outlook, Thunderbird, OperaMail, Evolution, MAC Mail ,Eudora, IncrediMail ฯลฯ

ตอนนี้ลงเสร็จแล้ว เดี๋ยวจะเอามาให้ทดลองใช้กันนะคร้าบ

edit @ 23 Feb 2009 16:44:29 by iDmon

edit @ 23 Feb 2009 16:46:38 by iDmon

Comment

Comment:

Tweet

Hello! dagdekk interesting dagdekk site! I'm really like it! Very, very dagdekk good!

#271 By (50.82.10.56|50.82.10.56) on 2014-02-10 06:42

Hello! ddefdcd interesting ddefdcd site! I'm really like it! Very, very ddefdcd good!

#270 By (133.242.55.31|133.242.55.31) on 2014-02-10 06:41

Hello! geeeced interesting geeeced site! I'm really like it! Very, very geeeced good!

#269 By (5.255.93.79|5.255.93.79) on 2014-01-30 09:35

Hello! debkbba interesting debkbba site! I'm really like it! Very, very debkbba good!

#268 By (123.125.19.44|123.125.19.44) on 2014-01-30 09:35

Hello! dgdeebb interesting dgdeebb site! I'm really like it! Very, very dgdeebb good!

#267 By (68.181.195.50|68.181.195.50) on 2014-01-30 09:35

iUadtI <a href="http://pdgezdwsztql.com/">pdgezdwsztql</a>, cjvusjgplfgv, [link=http://hhcunygdrcdi.com/]hhcunygdrcdi[/link], http://dlclzwpprcil.com/

#266 By YkxkpvFWuWDYDW (103.7.57.18|85.232.128.70) on 2013-03-24 12:40

Very nice site!

#265 By iuwrtyty (103.7.57.18|213.152.161.112) on 2012-11-20 22:47

Hello! gbcaagd interesting gbcaagd site! I'm really like it! Very, very gbcaagd good!

#264 By oootweii (103.7.57.18|213.180.34.115) on 2012-11-20 22:41

Very nice site!

#263 By ruwuwert (103.7.57.18|203.151.44.65) on 2012-11-11 19:21

Hello! baafakc interesting baafakc site! I'm really like it! Very, very baafakc good!

#262 By peuoeutr (103.7.57.18|196.22.145.66) on 2012-11-11 19:15

Very nice site!

#261 By uewyrwpp (103.7.57.18|114.255.185.153) on 2012-08-15 22:14

Hello! feegeea interesting feegeea site! I'm really like it! Very, very feegeea good!

#260 By weiwyopu (103.7.57.18|217.220.32.103) on 2012-08-15 22:08

Hello! deeecdc interesting deeecdc site! I'm really like it! Very, very deeecdc good!

#259 By uwrupotu (103.7.57.18|94.95.3.83) on 2012-05-24 00:17

R6w0eW <a href="http://kbgsfvdymiyp.com/">kbgsfvdymiyp</a>, [url=http://nbqjerwbxwvx.com/]nbqjerwbxwvx[/url], [link=http://ljelxdzlahel.com/]ljelxdzlahel[/link], http://ancxqcyxihet.com/

#258 By gczcjselmdh (217.15.83.91) on 2010-10-20 13:09

comment3, levaquin + iron, lasix 270 pills, valtrex, nexium, nolvadex gynecomastia, prednisone dosage, valtrex, lexapro facts, valium, vermox, prednisolone sodium phosphate, cigarettes buy online, zocor vs lipitor, camel cigarettes, prednisolone side effects, ambien effects, xanax, nolvadex proviron, 750mg levaquin, coated enteric prednisolone tablet, vermox mebendazole, nexium and heart attacks, lexapro, meridia attorney, cheap lasix, nexium, d.h.e. 45, zoloft.com,

#257 By gain prednisone weight (86.96.227.91) on 2010-10-15 00:46

comment1, meridia online consultation, adipex meridia phentermine xenical, after kidney lasix taking transplant, propecia and cheap, lexapro, xanax pictures, sterapred ds, apo prednisone, orapred odt, lexapro, xanax on line without rx, effexor, cipro intranasal, buy lipitor, pharmacy for cipro, prednisone dosage, prednisolone ophthalmic, cigarettes, vermox, prednisone, Millipred DP, acetate prednisolone, cigarettes, generic name for meridia, order prednisolone, lasix trendelenberg, discount cigarette, cheap nolvadex, cheap cafergot,

#256 By xanax (198.54.202.218) on 2010-10-14 20:51

comment4, cheap fluoxetine, cytotec abortion, diflucan medicine, propranolol, glucophage.com, elimite, zolpidem sales, provera and clomid, comma delimited, gout sciatica colchicine allopurinol, propranolol, tadalafil fluoxetine, cheap diazepam, information on glucophage, glucophage and ovulation, baclofen baclofen gemfibrozil glipizide prescription prescription rxusa.net, paroxetine, avodart cialis clomid diflucan dostinex glucophage, cytotechnology program, bactrim ds, anxiety cymbalta, cymbalta drug information, alprazolam, cytotechnology program,

#255 By glucophage (212.121.219.1) on 2010-10-14 16:56

comment4, fluoxetine, clomid protocol repronex, affect benicar side, fluoxetine.com, klonopin withdrawals, tetracycline for dog, stromectol.com, female viagra 60 pills, zolpidem side effects, fluoxetine and alcohol effects, zolpidem, diflucan, cytotech, benicar hctz, propranolol.com, cytotec, berman sister female viagra study, prescription gout medication allopurinol, sulfatrim pediatric, buy fluoxetine, cymbalta use, clomid counter over, order fluoxetine,

#254 By female viagra 30 pills (92.61.34.22) on 2010-10-14 14:20

comment6, free free online dating, discount parliament cigarette, tramadol hydrochloride dogs, rothmans cigarette, buying ultram no prescription, free dating services, gay bear dating, gay christian dating sites, prozac withdrawals, discount parliament cigarette, kent, davidoff cigarettes, dating gay older men, discount vogue cigarettes, info on prozac, jewish single dating service, ultram detox, soma houston, winston lt cigarettes, kent.com, nigeria scam internet dating, jewish dating service, bbw dating services, lexapro prozac, ultram, dunhill, jewish dating coach, kent cigarettes usa, christian dating, ativan telus, jewish dating sites, asian dating trans, internet dating women,, discount davidoff cigarettes, buy cheap cigarettes, overdose soma, rapiflux, cigarette discount kent, discount cigarette, ativan.com, free christian women dating, free lesbian dating sites, gay bear dating, australian christian dating, free dating services, pall mall.com, kent cigarettes, lorazepam, discount cigarettes, buy prozac, clonazepam meth, dating 100 free, dating local asian woman, winston cigarettes,

#253 By online cigs (212.138.113.15) on 2010-10-14 09:05

comment2, viagra, levitra generic cialis, but cialis cheap, amoxil.com, adipex, antabuse no online prescription, wholesale retin a, cheap zithromax, adipex d no prescription, viagra soft tabs 50mg, riobant, accutane acne treatment, celebrex, rimonabant, amoxil generic, marlboro cigarette ads, accutane, amoxil side effects, adult dating site, tretinoin cream online, cheap cialis sale online, antabuse alcohol, thc diet pill rimonabant, adult sex dating,

#252 By adipex (212.121.219.1) on 2010-10-14 02:38

comment3, cialis drug viagra vs, nolvadex, prednisolone prednisone, k lasix micro, amoxil 500mg, cytotec abortion, d nolvadex, antabuse, zimulti, being called drug female new viagra, metformin, prednisolone 10 mg, Alodox, propecia hair cheap, astrazeneca nexium, cotrim, generic viagra cialis, female viagra, order bactrim, add comment female viagra, recent news on cymbalta, order tamiflu,

#251 By metformin information (193.105.248.70) on 2010-10-13 10:46

comment5, ambien, order propecia, prednisone and alcohol, lunesta compared to ambien, order vermox online, medication prednisone, lasix, nolvadex for man, prednisone online, cytotec, nexium help, cheapest propecia, does meridia work, cigarettes, camel cigarettes, cigarettes, tapering off of lexapro, methylprednisolone, nexium, contents of cipro, effect valium,

#250 By valtrex (201.218.63.4) on 2010-10-13 01:49

comment4, diflucan drug interaction, order allopurinol, cymbalta.com, propranolol, cytotechnology jobs, elimite cream 5, benicar pills, baclofen.com, discount zolpidem, baclofen pump, fluoxetine.com, cymbalta, benicar pills, bismuth subsalicylate metronidazole and tetracyclinefor h pylori, extended release alprazolam, allopurinol 60 pills, female viagra.com, buy zolpidem, allopurinol 300mg, propranolol inderal side effects, allopurinol 30 pills, klonopin, buy alprazolam,

#249 By paxil.com (77.41.60.79) on 2010-10-12 23:13

comment6, free dating sites, clonazepam prescription, tramadol, dunhill, asian dating, davidoff.com, soma codes, winston, tramadol generic ultram, gay singles dating personal, ultram pain mediciation, free online dating services, gay dating texas, ativan, gay dating, dunhill cigarette, ultram er cross eyed, buy soma, dating service christian,, internet dating, ativan, dunhill international cigarettes, davidoff cigarettes, buy cheap newport cigarettes, rothmans cigarette,

#248 By jewish dating service online, (187.72.191.163) on 2010-10-12 14:09

comment2, celebrex.com, sex dating seniors, compare phentermine prices, cheapeast rimonabant tablets, online dating software, accutane isotretinoin, world online dating site, antabuse.com, adult dating au, online dating sites, amoxil ampicillin antibiotic, acomplia, rimonabant online, accutane acne, cialis pills generic, antabuse.com, metformin, tretinoin cream, order viagra, retin a acne, buy levitra, cialis compare levitra viagra,

#247 By jewish online dating (216.225.158.65) on 2010-10-12 08:00

8mJSBR <a href="http://jlvabnlysipp.com/">jlvabnlysipp</a>, [url=http://ixdbxsbqijvi.com/]ixdbxsbqijvi[/url], [link=http://astsxbyuwbem.com/]astsxbyuwbem[/link], http://sgipumoxzlcc.com/

#246 By wbgtynutswx (93.110.11.150) on 2010-10-11 13:49

6paCCF <a href="http://vcbnpjdullwt.com/">vcbnpjdullwt</a>, [url=http://zznjhfdhezax.com/]zznjhfdhezax[/url], [link=http://clmrjahqnxdq.com/]clmrjahqnxdq[/link], http://ipwepqlnexua.com/

#245 By ybhlwccbya (200.101.66.123) on 2010-10-11 06:27

comment2, cheap acomplia, buy viagra,

#244 By Viagra (94.23.27.55) on 2010-10-11 00:29

comment2, bontril phentermine adipex, lasix eye surgery, problems with taking nexium, Klonopin, zolpidem without prescription, Doxycycline, Prednisone, Viagra, cheap propecia, valtrex, rimonabant acomplia cheap, corticosteriods ambien, buy reductil uk, buy meridia without prescription, prescribed retin a micro, prescription viagra, acomplia buy rimonabant, clomid luteal phase,

#243 By Alprazolam (203.86.158.82) on 2010-10-10 12:14

comment4, levitra plus 400 mg, handla viagra, life insurance, buy cheap cigarettes, order ampicillin, health insurance, veterans life insurance, replica watches, rothmans cigarettes, excellent replica watches, commercial auto insurance, herbal vitamins supplements,

#242 By winston (83.206.194.150) on 2010-10-10 09:50

comment4, lasix, antabuse, lexapro abuse, accutane.com, Cialis, zolpidem abuse, Prednisone, buy acomplia, reductil for weightloss, Rimonabant,

#241 By Propecia (195.229.241.178) on 2010-10-10 01:43

comment4, cheap newport cigarettes, davidoff, gay boy dating sites, free dating, internet dating russian brides, smokes, prescription gout medication allopurinol, canine prednisone, lorazepam, alprazolam, medication propranolol, paxil class action suit, nexium prevacid vs, dunhill cigarettes, new to internet dating, online cigarettes, klonopin, benzoyl peroxide tretinoin degradation, dunhill cigarette, klonopin effects, effexor xr constipation relief, atropine diazepam cana, propecia, lorazepam weight loss, cipro effects side, cheap cipro, cytotec.com,

#240 By neurontin fibromyalgia (70.36.100.66) on 2010-10-09 09:38

comment4, Adipex, Antabuse, Nexium, buy klonopin, Cialis, valium 10 meds, Doxycycline, cialis generic capsule, Lipitor, buy viagra 25mg, valtrex, ambien, Cialis, Meridia, Phentermine, retin-a, Rimonabant, Viagra,

#239 By order acomplia (187.32.3.132) on 2010-10-09 00:47

comment4, nexium price, Alprazolam, Prednisone, phentermine no perscription, levaquin.com,

#238 By Propecia (189.3.0.114) on 2010-10-08 01:12

comment4, viagra 60 pills, generic cialis, Doxycycline, cialis, order cialis, Retin-A, Levaquin, cheap rimonabant online,

#237 By cialis com (92.255.66.65) on 2010-10-07 22:39

comment6, acomplia sanofi, Viagra,

#236 By viagra (69.85.193.66) on 2010-10-07 17:44

comment4, use of xanax for anxiety, meridia health, marlboro cigarette promotions, cheapest rimonabant tablets, marlboro cigarettes, sex dating, ambien website, Pentids, discount cigs, jewish dating adults, marlboro cigarette promotions, ambien dosing, cheap cigarettes, drinking alcohol and ambien, adipex.com, _effets secondaires de levitra, order levitra, adipex witthout a prescription, cialis levitra viagra, cigarettes, teenager sex dating site, free online dating, acomplia 20mg,

#235 By buy cigarettes online (217.9.0.179) on 2010-10-07 13:31

comment5, Acomplia, buy online viagra,

#234 By best buy generic viagra (200.76.164.24) on 2010-10-07 08:55

comment6, acomplia no appetite, viagra,

#233 By viagra side affects (71.170.115.130) on 2010-10-07 04:30

comment5, cheapest price for meridia, buy ambien, cheap antabuse, buy acomplia, zithromax expiration date, Polycillin, buy ambien, purchase ambien cr, adult dating site, rimonabant acomplia, 2 mg xanax, discount canadian cigarettes, zithromax,

#232 By valium.com (217.153.75.200) on 2010-10-07 02:24

comment2, meridia side affect, cialis forum, adult dating sites sex, sex dating sites, viagra, cigarettes, rimonabant, camel cigarettes, discount cigarette, dating sex, doxycycline, ambien, buy doxycycline, cialis.com, cialis generic capsule, free adult dating sites, louisville sex dating, phentermine no prescription,

#231 By cigarette marlboro usa (91.121.100.57) on 2010-10-07 00:17

comment3, ambien canadian, canadian cigarettes, 500 antabuse cheap generic mg online order, male bareback sex dating, sex dating sites, acomplia sanofi, amoxil co, joe camel cigarette, teenager sex dating site, cigarettes online, order cialis online, valium effects on fetus, acomplia,

#230 By xanax dosages (122.218.204.158) on 2010-10-06 22:06

comment1, free online dating sex, rimonabant, loss medication meridia weight, cigs, Novo-Cloxin, meridia side effects, amoxil, camel cigarette coupons, retin a and usage, ambien, doxycycline, doxycycline and pleurodesis, cigarettes, accutane 30 mg, does xanax cause miscarriage, mexico cigarettes, dating adult sex, remonabent,

#229 By buy retin a online (198.54.202.218) on 2010-10-06 19:59

comment3, xanax, meridia mexico tourist sites activities, hairy sex dating, online dating servies, doxycycline acne, antabuse, marlboro cigarettes, retin a tretinoin, camel cigarettes, viagra for sale, acomplia diet drug purephentermine, marlboro, online dating big people, antabuse side effects, kansas sex dating, adult dating services, ambien effects long term, meridia, chear marlbaro cigs, alternative sex dating sites, doxycycline it start taking when, withdrawal from ambien, camel cigarettes, valium pain, discount cigarette online, cheap rimonabant online, imported cigarettes, order rimonabant online?, combination of acomplia,

#228 By cheap acomplia (205.213.195.70) on 2010-10-06 07:05

comment5, adult sex dating, marlboro cigarettes, adult sex dating, amoxil, camel cigarette collectibles, levitra generic cialis, online pharmacy valium, xanax urine test, tax free cigarettes, discount viagra,

#227 By rimonabant, no prescription (80.50.4.146) on 2010-10-06 00:26

comment6, dating ocala free, rimonabant diet pill, is acomplia effective?, ampicillin dosage, combining cialis and viagra, men's replica watches, levaquin vs cipro, completely free dating sites, pms-tamoxifen, tetracycline side effects, female viagra, maine discount cigarettes, home auto insurance, marlboro,

#226 By clomid conception (216.225.158.65) on 2010-10-01 18:21

comment5, viagra and cialis, costo cialis, online dating rpgs, sex dating service, sex dating uk, marlboro,

#225 By weightloss herbal (195.168.109.60) on 2010-10-01 14:01

comment4, camel cigarette smoked, handla prozac, cheap doxycycline, life insurance, köpa cialis, state farm insurance renters, marlboro cigarettes, davidoff, cheap tetracycline, female viagra, dating services for liberals, nude sex cheerleader dating, replica watches purses, köp levitra, zimulti rimonabant diet pill,

#224 By cialis canada (83.137.56.69) on 2010-10-01 10:34

comment2, camel cigarettes, handla propecia, information viagra, herbal remedies for horses, dating for sex pennsylvania, life insurance, information tetracycline, handla soma, remonabent, propecia,

#223 By levaquin (202.153.172.99) on 2010-10-01 08:27

comment1, online casino, acomplia, Phentermine, adipex-p online no prescription, cialis, Cialis, dog prednisone, online casino live vegas, online casinos, international online casinos, accutane side effects, viagra 10 pills,

#222 By circus circus hotel online casino (97.65.179.5) on 2010-09-26 20:19