RHCE学习笔记-253-2

electronic mail services(sendmail,postfix)
sendmail features
支持许多种不同邮件地址的格式
TCP/IP user@hostname
BitNet
UUCP
FidoNet
MCImail
可以伪装邮寄者寄出去的邮件
当传送失败自动重试
security and “anti-spam” features
安全性特性
如果无法解析地址就退回这封信笺
完全控制用户、电脑、domains是否可以寄信
默认只允许到本地MAIL SERVER的传送
反垃圾邮件特性
默认不帮其他MAIL SERVER relay
设定database,定义用户是否可以发送邮件
Email header checks
在MAIL SERVER上使用spamassassin进行邮件过滤
an email review
Mail User Agent(MUA)
一般使用者使用的邮件客户端,如outlook express
Mail Transport Agent(MTA)
如sendmail就是MTA的一种
Mail Delivery Agent(MDA)
当MTA把信笺收到时,还通过MDA负责将信笺放到收信人的mail box里,MDA还有一个可以过滤邮件的功能,有写mail server会同时扮演MTA和MDA的角色,如exchange server,sendmail只负责MTA,MDA由procmail负责
MUA发送邮件到MTA,端口25,MTA判断是否为本机信笺,如是,交给MDA,MDA将信笺放入收件人的mail box,/var/spool/mail;如不是,MTA将信放入mail queue,/var/spool/mqueue,然后将信转送给负责收件人MAIL的mail server,这个转送的动作叫relay。要先到DNS SERVER查找相关的MX记录,relay时也是使用端口25,同样目的MAIL SERVERR也会判断是否是本地邮件
servere operations(mail server工作流程)
1. 用户通过MUA通过进程mail submission program(MSP)连接到本地MTA
2. 本地MTA到DNS上查询目的的MX记录
3. 本地MTA通过TCP/IP 25 port 连接目的MX
4. 两端的mail server通过SMTP协议建立连接(25 port)
5. 目的MAIL SERVER收到邮件后判断是否是本地邮件,不是本地邮件继续relay
service profile:sendmail
type system V-managed service
packages sendmail{,-cf}
daemons sendmail
script sendmail
ports 25(smtp)
configuration /etc/mail/sendmail.cf, /etc/mail/submit.cf, /etc/aliases, /etc/mail/*
related procmail
log file /var/log/maillog
main configuration files
/etc/mail/sendmail.cf配置sendmail
包含了邮件网域别名管理,relay rules,等
当sendmail在呼叫用户的程序(MSP)时,会使用/etc/mail/submit.cf设置
但通常不会修改这个设置
[root@host samba]# netstat -tupln | grep 25
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1917/sendmail: acce
vi /etc/mail/sendmail.cf
#O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA
[root@host samba]# /etc/init.d/sendmail restart
[root@host samba]# netstat -tupln | grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6490/sendmail: ace
telnet example.example.com 25
HELO example
MAIL from:user@example.com
RCPT to:tom@example.com
DATA
this is a test mail!
.
quit
如果使用telnet命令登陆MAIL的25端口,中途要离开的话输入ctrl+],回车
telnet>quit
other configuration files
/etc/aliases 定义用户别名,一个别名可以定义多个用户,用在向部门发信时
在更新完aliases后, 需要用命令newaliases更新aliases.db
/etc/mail/local-host-names
设定网域别名和网域名称,决定了mail server要接受哪些进来的mail,哪些mail是本地的。
sendmail configuration with the m4 macro language
sendmail可以通过m4 macro language来设置
m4是一种macro语言,称聚集处理器,可以帮助我们设置sendmail.cf
欲设档存在/etc/mail/sendmail.mc
由于sendmail.cf设置非常复杂,所以建议修改sendmail.mc来编译成sendmail.cf
要使用m4,必须安装了sendmail-cf 及m4-*聚集处理器RPM套件
sendmail m4 macro file:introduction
所有的sendmail.mc都会定义OS type,file locations,desired features…
vi /etc/mail/sendmail.mc
dnl # =Delete New Line 表示dnl后面是注解
OSTYPE(`linux’)dnl
define(`ALIAS_FILE’, `/etc/aliases’)dnl
sendmail m4 macro file:features
FEATURE设定
dnl # DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6’)dnl
#FEATURE(`accept_unresolvable_domains’)dnl
修改后使用m4命令
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
diff /etc/mail/sendmail.cf /etc/mail/sendmail.cf.bak
sendmail client configuration
在大规模的组织里可能有多个mail server,有一个mail gateway,其他的mail server叫mail client
所以central mail server(mail gateway)上必须可以接受进来的mail和要relay的mail
而mail client上可以根据需求看要使用MAIL_HUB或者SMART_HOST,或者2种都使用
MAIL_HUB是将公司里客户端寄过来的mail全部都交给mail.domain.com这台mail gateway寄发出去
在sendmail.mc里加上
define(‘MAIL_HUB’,’mail.domain.com’)dnl
SMART_HOST
to deliver local mail locally but relay outgoing mail through mail.domain.com
define(‘SMART_HOST’,’mail.domain.com’)dnl

通常在使用mail gateway时,会配合masquerade功能将来信的from伪装成某个domian的名称
MASQUERADE_AS(‘domain.com’) dnl
FEATURE(‘allmasquerade’) dnl
FEATURE(‘masquerade_envelope’) dnl
other valuable m4 directives
FEATURE(‘dnsbl’)
checks a DNS implemented blackhole list to block email spammers
FEATURE(‘relay_based_on_MX’)
automatically allows relaying if sendmail server is listed as the target domain’s MX record
additional sendmail configuration files
/etc/mail/ 默认是存放sendmail设置的目录
virtusertable 虚拟的邮件地址对应到哪个真实的邮件地址
access 设置来自某个地址的邮件拒绝或接受
/etc/mail/virtusertable
允许多个虚拟domian和users对应到其他的email地址
/etc/mail/access
used to accept or deny incoming email
OK accepts mail
RELAY accepts mail for relaying
REJECT rejects the sender
DISCARD discard the mail
在修改完access文件后,make,要在/etc/mail里执行
/blacklisting recipients
在sendmail.mc里设置(默认已经有了)
FEATURE(‘blacklist_recipients’)
any entry in the access file that has a REJECT or returns an error code will be a blacklisted recipient
debugging sendmail
当sendmail没有收到任何邮件时,检查
/etc/mail/local-host-names
看里面是否设置了mail server的domain名称及别名
mail -v user
寄发email,检查SMTP的交换信息以本地的relay状况
mailq
在mail server查看将来要传送的mail queued
mailq -Ac
在客户端查看/var/spool/clientmqueue有哪些要传送到mail server的信件
tail -f /var/log/maillog
安装POP SERVER让邮件的使用者可以通过POP3(110)协议将使用者的mail从mail server上下载到本地
rpm -qa | grep dovecot
需要安装dovecot 套件
vi /etc/dovecot.conf
#protocols = imap imaps #imap不会将使用者的mail下载到本地
protocols = pop3 pop3s
services dovecot restart
在客户端使用telnet mail.domain.com 110
建议使用GUI界面,rpm -qa | grep mozilla-mail
rpm -ivh mozilla-mail-1.7.3-18.EL4.i386.rpm --aid
安装完后,执行mozilla &
点选window–mail & newsgroupss
using alternatives
使用alternatives的功能来切换另外一个版本的mail server的服务
可能有不同的套件提供同一个服务,alternatives就是来管理使用哪个套件来提供服务
only the links in /etc/alternatives/ are modified
ls -l /etc/alternatives/
to display which MTA alternative is in use:
alternatives --display mta
to choose from the available MTA alternatives from the command line:
alternatives – config mta
system-switch-mail
要安装rpm套件
rpm -ivh system-switch-mail*
postfix
可以代替sendmail
可以达成
postfix可以和sendmail兼容
执行速度比sendmail快,系统负荷低
易于管理
某些方面比sendmail安全
service profile:postfix
type system V-managed service
packages postfix
daemons master,nqmgr,smtpd,pickup
script postfix
ports 25(smtp)
configuration /etc/postfix/main.cf
related procmail
configuring postfix
installation postfix RPM package
activate with alternative
set up minimal configuration directives
vi /etc/postfix/main.cf
#inet_interfaces = localhost
inet_interfaces = all
设置所有的ip可以寄信到这台服务器
mydestination = m y h o s t n a m e , l o c a l h o s t , myhostname,localhost, myhostname,localhost,mydomain,localhost
设置哪些domian视为本地的邮件,而不再relay出去
mynetworks = 192.168.0/24,127.0.0.0/8
允许relay哪些地址来的信笺
myorigin = domain.com
所有邮寄出去的信笺地址后面都改为domain.com
start with service
additional postfix configuration
/etc/postfix/下有些配置文件其语法和功能和/etc/mail/下sendmail设置档一样
virtual - virtual domain mapping
access - mail routing controls
/etc/aliases can be used by postfix,as is
procmail delivery
procmail is a very powerful delivery tool
additional MTA configuration may be required(有些MTA可能需要额外的配置,像postfix默认不会使用procmail这个邮件过滤器)
vi /etc/postfix/main.cf
mailbox_command = /usr/bin/procmail
service postfix restart
启用后如果想对所有用户应用过滤规则需配置/etc/procmailrc
如果想对某个用户应用过滤规则,配置$HOME/.procmailrc
procmail sample configuration
ls /etc/procmailrc
ls $HOME/.procmailrc
vi KaTeX parse error: Expected 'EOF', got '#' at position 28: …ilrc :0 b #̲b是move的意思,指把垃圾邮…HOME/public_html/
每个用户都有自己的网站默认存放在/ H O M E / p u b l i c h t m l / s u − t o m m k d i r / HOME/public_html/ su - tom mkdir / HOME/publichtml/sutommkdir/HOME/public_html
cd public_html
vi index.html
tom’s website
vi /etc/httpd/conf/httpd.conf
#UserDir disable
ls -dl /home/tom
ls -dl /home/tom/public_html
查看权限区别,
chown o+x /home/tom
virtual hosts
在一台web server上设置多个网址,支持多个website
apache access configuration
控制电脑允许与否访问网页
可以用network/netmask 192.168.1.0/255.255.255.0或用hostname及domains
是通过order这个参数来提供控制存取的先后顺序
vi /etc/httpd/conf/httpd.conf
Order allow,deny
Allow from all
某些时候结果不会是预期
order allow,deny
如果后面没有具体的记录,默认会是deny
order deny ,allow
如果后面没有具体的记录,默认会是allow
order allow,deny
deny from *domain.com
除了拒绝domian.com之外还拒绝其他的
order deny,allow
deny from .domain.com
除了
.domain.com拒绝外,其他允许
order allow,deny
allow from domain.com
允许
.domain.com外,其他拒绝
using .htaccess files
使用这个文件可以让使用者在浏览某个页面时出现验证窗口,来控制使用者的存取
mkdir /var/www/html/tips
vi /var/www/html/tips/index.html
this is a test
打开http://192.168.0.1/tips
假设我们要让使用者访问这个页面的时候输入验证信息
vi /etc/httpd/conf/httpd.conf
<Directory “/var/www/html/tips”>
AllowOverride authconfig

<Direcoty “/var/www/html/”>
cd /var/www/html/tips
vi .htaccess
AuthName “htaccess” #随便输入,是登陆的提示
AuthType basic #用户身份验证资料使用Unicode编码
AuthUserFile /var/www/html/tips/wwwpasswd #设置验证身份的档案存储位置
require valid-user #设置必须通过验证的合法使用者才能存取
cd tips
htpasswd -c wwwpasswd tom #第一次用-c,以后就不需要-c了
service httpd restart
控制电脑访问,可以在httpd.conf里
order deny,allow
deny from *.domain.com
控制用户访问,在.htaccess里
CGI(Common Gateway Interface)

CGI程序可以用ScriptAlias的设置将CGI的目录限制在某个目录里
ScriptAlias /cgi-bin/ / /cgi-bin/
vi /etc/httpd/conf/httpd.conf
ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
另外CGI可以载入像mod-perl这样的modules来加快CGI的执行速度
notable apache modules
mod_perl
mod_php
vi /var/www/html/test.php
<? phpinfo(); ?>
http://192.168.0.1/test.php
mod_speling
可以自动检查客户端输入的URLs
squid web proxy cache(Proxy Server)
Squid uses port 3128 by default,but can easily be changed to 8080 if required
Like Sendmail,the default Squid configuration only accepts connections on the system’s lookback interface
service profile :squid
type system V-managed service
packages squid
daemons squid
script squid
ports 3128(squid)
configuration /etc/squid/squid.conf
vi /etc/squid/squid.conf
http_port 3128
#acl localhost src 127.0.0.1/255.255.255.255
acl localhost src 127.0.0.1/255.255.255.255
http_access allow manager localhost
acl domain src 192.168.8.0/24
在客户端IE里设置网络代理即可

Authentication services
User Authentiaction
two types of information must always be provided for each user account
account information:UID,default shell,home directory,group memberships,and so on
/etc/passwd里面的内容
authentication:a mechanism to verify the password for account credential at login
/etc/shadow里面的内容
Account Information
Name services accessed through library functions map names to information
Originally,name service was provided only by local files like /etc/passwd
Normally applications do not search in the /etc/passwd directory for this information
applications use standard library functions provided by the system’s standard C library,libc,to look it up
adding support for new services (such as NIS) required rewriting libc
Name Service Switch(NSS)
NSS is mechanism which allows configuration and extension of the name services supported by libc
uses /lib/libnss_service.so files
for example, /lib/libnss_files.so provides support for retrieving name service information from the standard local files
/etc/nsswitch.conf controls which name services to check in what order
passwd:files nis ldap #表示先查看本地/etc/passwd然后nis,ldap
getent
如何取得本地及网络上所有可使用的帐户信息
getent database
lists all objects stored in the specified database
eg:getnet passwd
getent database name
looks up the information stored in the specified database for a particular name
eg: getent passwd tom
Authentication
applications traditionally authenticated password by using libc functions
hashes password provided on login
compare to hashed password in NSS
If the hashes match authentication passes
PAM
pluggable authentication modules (/lib/security/pam_*.so, /etc/pam.d/login)
application calls libpam functions to authenticated and authorize users
libpam handles checks based on the applications PAM configuration file
shared, dynamically configurable code
PAM Operation PAM怎么运作
/lib/security PAM modules
each module performs a pass or fail test
file in /etc/security may affect how some modules perform their tests
/etc/pam.d PAM configuration
service files determine how and when modules are used by particular programs
/etc/pam.d Files:Tests
tests are organized into four groups
四种测试类型
auth authenticates the user identity 验证使用者的帐号
account authorizes the account may be used 用来确认使用者帐号是否有效,并授权给使用者,比如限制用户在某个时间段登陆进来,那么即使通过auth也可能不能登陆
password 使用者变更密码的时候是由这种验证类型来控制的
session 当一个session被opens,closes,PAM都会呼叫这种验证类型来记录这个session
each group is called as needed and provides a separate result to the service
libpam函数库里面的模块会是呼叫以上全部的服务或者只是呼叫其中一个服务由模块本身的功能来决定
/etc/pam.d Files:Control Values=control flag
定义了有哪四种VALUES,控制验证是否成功的标准,control values用来定义我们在前一个小节中所介绍的4种测试类型档案可以有哪些结果
required 当模块设置为这种控制标准的时候,那么使用这种模块验证使用者的结果就一定要成功,如果没有成功仍然往下测试,并在所有测试结束后返回失败信息,这样做是不让用户知道是在哪一个阶段失败的
requisite 也一定要成功,如果没有成功的话,PAM会立刻把失败的信息传个应用程序,而不会继续往下测试
sufficient 当使用者测试时,PAM会立刻把验证成功的信息传个应用程序,并且不会继续往下测试,如果使用者没有通过测试的话,PAM会忽略掉这个结果,继续往下测试
optional 当模块设置为这种控制标准的时候,那么无论测试结果怎么样都不会影响到PAM的运做,通常我们会把session类型的档案设置为这种控制标准
在这里插入图片描述

P为pass,f为fail,y为yes,n为no
在这里插入图片描述
在这里插入图片描述

Example /etc/pam.d/File 文件格式
在这里插入图片描述

每一行都是一个阶段的验证过程
第一阶段,影响到使用者能不能通过验证,得到应用程序提供的服务
第二阶段,只有在使用者变更密码的时候才会使用到
第三阶段,当使用者通过验证后用来变更使用者的执行环境并且记录所有被执行的session
pam_stack
介绍这个特殊的模块
如果有很多应用程序要使用一组同样顺序的验证程序来验证使用者的话,那么我们可以另外编辑一个PAM设置文件,在这里定义好这种验证的程序,然后把这个档案放到/etc/pam.d/下,再让所有需要使用这种验证的应用程序来呼叫这个档案,这样我们就不需要在每个应用程序所对应的PAM设置档里面定义这一组程序,也就是说只要变更这个档案里的设置,就可以影响到很多应用程序的验证程序。
在应用程序所对应的PAM设置档里面,会使用pam_stack这个模块来呼叫/etc/pam.d/下面的PAM设置档,并依据这些设置档里面的设置去呼叫出其他的模块来验证使用者
例如有很多应用程序会通过pam_stack这个模块来呼叫/etc/pam.d/system-auth这个设置档
在这个设置档里面定义好了一组标准的验证程序,让系统里面不同的应用程序可以通过这个档案里面的设置呼叫出其他的模块来验证使用者,那么可以修改/etc/pam.d/system-auth这个文件的设置方便的修改系统标准的验证过程
pam_unix
这个模块可以呼叫出传统的NSS系统,也就是libnss函数库中的模块来验证使用者,可以使用在PAM的4种验证类型中
auth PAM可以通过NSS的模块取得存储在系统里面重新编码过的使用者密码,并把使用者登陆时要求输入的密码重新编码后比对是否一致来决定使用者是否可以通过验证
account PAM通过NSS确认使用这帐号是否有效
password 当使用这要变更存储在本地或NIS的密码时,PAM可以通过NSS模块来控制变更密码的验证程序
session PAM可以通过NSS的模块来记录使用者登陆以及登出时的logs
Network Authentication
介绍有哪些方式可以验证网络上的使用者
在我们的环境中有使用集中管理密码的服务器的话,可以配合以下4种模块来验证使用者
pam_krb5 Kerberos V tickets
pam_ldap LDAP binds
pam_smb_auth old SMB authentication 传统的SMB服务器使用的验证方式
pam_winbind SMB through winbind 这是使用winbindd服务的SMB服务器的验证方式
pam_smb_auth和pam_winbind是2种整合异构平台验证的技术,可以把验证使用者的工作交给微软的DC来做
以上提到的名称服务也可以交给NSS/pam_unix去做
如:NSS,hesiod,某些LDAP当中的设置
auth Modules
介绍还有哪些模块会影响验证的结果
pam_securetty只会对root帐户产生影响,当root这个帐户要求登陆到virtual console或serial terminal的时候会去参考/etc/securetty里面有无列出,看看root能否登陆
pam_nologin 先去确认在/etc/nologin文件存在不存在,若存在,其他不是root的使用者都会验证失败,也就是只有root才能通过验证

pam_lisfile 这个模块会去确认要求登陆的使用者帐户与允许登陆到系统中的使用者名单有没有冲突,我们必须提前编辑一个允许登陆和拒绝登陆的列表
auth required pam_listfile item=user sense=deny file=/etc/vsftpd.ftpusers onerr=succeed
Password Security
有哪些方式可以让使用这的密码变的更具有安全性
pam_unix MD5 password hashes
makes password hashes harder to crack
pam_unix shadow passwords
makes password hashes visible only to root
makes password aging available
other modules may support password aging mechanisms
Password Policy
password history
pam_unix with remember=N argument
记录密码历史,记录前n个密码
password strength
pam_cracklib 密码复杂性,长度,不在字典内。
pam_passwdqc 密码复杂性,长度。
failed login monitoring
pam_tally 失败锁定策略
session Modules
介绍使用者通过验证后,有哪些session模块可以限制
pam_limits 限制使用者所能使用的系统资源
/etc/security/limits.conf
可以使用ulimit,会覆盖掉soft limit,但是hard limit不会被覆盖掉
pam_console sets permissions on local devices for console users,当使用这是坐在主机前通过console登陆的时候,系统会开放一些特别的权限给这个使用者
/etc/security/console.perms 定义使用者登陆到哪些console时要给他们这些特别的权限
/etc/security/console.apprs 这里定义要开放的权限
Utilities and Authentication
除了验证使用者能不能登陆到系统里之外,PAM还可以为哪些应用程序提供验证使用者身份的服务
1. 当使用者要使用系统里面的管理工具的时候
su,reboot,system-config-*…
2. pam_rootok这个模块来确认要求使用这些管理工具的使用者是否是root
3. pam_timestamp会记录哪个使用者在什么时候做了什么事情,如果这个使用者在5分钟内认证通过的话就直接通过验证而不输入密码。
4. pam_xauth 当使用者通过这个模块验证成功后,会把使用者验证使用资料的缓存档转送给其他的应用程序
PAM Troubleshooting
check the system logs
/var/log/messages
/var/log/secure
PAM mistakes can lock out the root user
single-user mode bypasses PAM
boot the system using a rescue disc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骆驼1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值