分类: LINUX
2010-06-13 18:08:20
一、NFS
nfs
vim /etc/exports
/var/ftp/pub 192.168.0.0/24(rw,no_root_squash,sync)
exportfs -v 查看隐藏条件。
showmount -e hostname 查看已共享的目录。
rpcinfo -p hostname 查看某个计算机开启的rpc端口。
二、vsftpd
查询一个服务是否受tcp-wrappers支持两种方法。
ldd 'which vsftpd' |grep libwrap
strings 'which vsftpd' |grep hosts
禁止用户交换式登录
#usermod -s /sbin/nologin username
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES 是否允许匿名用户访问FTP。
#
# Uncomment this to allow local users to log in.
local_enable=YES 是否允许本地用户登录。(如为NO,则表示只允许虚拟用户登录。)
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES 是否允许用户写入FTP目录。
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022 本地用户上传文件的默认权限是644。
anon_umask=022 使匿名用户可以下载。
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES 是否允许匿名用户具有上传的权限。
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES 是否允许匿名用户创建目录
anon_other_write_enable=YES 是否允许匿名用户删除文件
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES 开启默认访问的消息功能。
#
# Activate logging of uploads/downloads.
xferlog_enable=YES 是否开启用户上传、下载的日志功能。
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES 是否开启主动传输模式。
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES 是否改变匿名用户上传的权限
#chown_username=whoever 是否改变匿名用户上传文件的所有人
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log ftpd日志的记录路径。
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES 是否使用标准的ftpd日志。(可兼容旧版的ftp。)
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600 如登录后没有操作,600秒后将会自动断开连接。
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120 数据连接最长时间为120秒,如超时,则自动踢掉。
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure 指定某个用户管理ftp
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES 是否允许运行特殊的ftp命令async ABOR.
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES 是否开启ASCII的上传和下载功能
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service. 定制欢迎信息
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails 是否允许禁止匿名用户使用邮件地址登录
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES 是否禁止用户切换到上一级目录。
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES 禁止用户使用ls -R 进行递归查寻。缺省是禁止的,如取消注释,则表示允许。
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES 缺省侦听在ipv4
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd whith two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES 如需侦听在ipv6,则取消注释。
pam_service_name=vsftpd
userlist_enable=YES 是否加载pam.d(/etc/pam.d/vsftpd)模块。
tcp_wrappers=YES
在/var/ftp下建立3G、2G两个子目录。
1.3G
要求user对该目录有所有的权限,而其他用户(非匿名)对其只能上传,不能删除。
2.2G
要求其目录中的txt1、txt2、txt3三个文件不能删除。其他所有文件对所有用户均开启全部权限。
三、Samba
显示服务器上的共享列表
#smbclient -L //192.168.0.36
将本地用户添加到samba数据库
#smbpasswd -a username
修改已存在的samba帐户的密码
#smbpasswd username
# %m∶代表 Client 端的 NetBIOS 主机名称喔!
# %M∶代表 Client 端的 Internet 主机名称喔!就是 HOSTNAME。
# %L∶代表 SAMBA 主机的 NetBIOS 主机名称。
# %H∶代表使用者的家目录。
# %U∶代表目前登入的使用者的使用者名称
# %g∶代表登入的使用者的群组名称。
# %h∶代表目前这部 SAMBA 主机的 HOSTNAME 喔!注意是 hostname 不是 NetBIOS name 喔!
# %I∶代表 Client 的 IP 咯。
# %T∶代表目前的日期与时间
testparm /etc/samba/smb.conf station1.example.com 192.168.0.1
在服务器端查看某主机可查看到的共享目录信息。
smbclient -L //192.168.0.36 显示该主机的共享列表
mount -t cifs //192.168.0.36/shared /mnt -o username=redhat%password 将远程主机的共享目录挂载到本地
smbclient //192.168.0.36/shared 匿名身份访问共享目录
smbclient //192.168.0.36/shared -U redhat 用户身份访问共享目录
案例。
1.创建redhat共享目录,但远程用户访问shared文件夹
2.仅允许192.168.0.0/24可以访问
3.仅允许user1、redhat对该目录有写的权限,其他用户均为只读。
4.允许所有人可以浏览,但拒绝匿名用户访问。
[shared] 远程用户访问的文件夹
comment = redhat directory 对该共享目录的描述(非必须)
path = /redhat 被共享文件夹的真实路径
writable = no 使用smb自身权限控制用户写入的权限
write list = @redhat,user1 可写入的用户列表。(writable = no时此项方可生效,否则所有用户均可写入)
browseable = no 控制用户是否可以浏览该共享文件夹
public = yes 匿名用户能否访问。
guest = ok 同上。两者若冲突,则按顺序,后者生效。
valid users = user2 仅允许此项指定的用户有操作的权限,而以上对用户的访问权限则无效。写入权限不受影响。
printable = no 如为yes则该目录则被认定为打印机(缺省为no)。
group = redhat 则无论上传者是谁。拥有组均为该行所指定的组。
查看samba数据库
tdbdump /etc/samba/passdb.tdb
虚拟用户
username map = /etc/samba/smbusers
#vim /etc/samba/smbusers
>user2 = admin1 admin 2
开机挂载/etc/fstab
vim /etc/samba/cred.txt 文件名任意
>username=user2
>password=redhat
chmod 400 cred.txt 防止
//192.168.0.36/shared /mnt cifs credentials=/etc/samba/cred.txt 0 0
自动挂载
子配置文件。
案例:要求仅user2用户可以浏览shared共享目录。
在全局加上config file = /etc/samba/smb.%U.conf
cp smb.conf smb.user2.conf
vim smb.user2.conf
browseable = yes
smbclient -L //192.168.0.36 -U user2
测试成功。