1、建立samba共享,共享目录为/data,要求:(描述完整的过程)
1)共享名为shared,工作组为magedu;
2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名;
3)添加samba用户gentoo,centos和ubuntu,密码均为“mageedu”;
4)此samba共享shared仅允许develop组具有写权限,其他用户只能以只读方式访问;
5)此samba共享服务仅允许来自于172.16.0.0/16网络的主机访问;
[root@centos ~]# yum info samba Name : samba Arch : x86_64 Version : 3.6.23 Release : 35.el6_8 Size : 5.1 M Repo : updates Summary : Server and Client software to interoperate with Windows machines 用于和windows共享 URL : http://www.samba.org/ License : GPLv3+ and LGPLv3+ Description : : Samba is the suite of programs by which a lot of PC-related : machines share files, printers, and other information (such as : lists of available files and printers). The Windows NT, OS/2, and : Linux operating systems support this natively, and add-on packages : can enable the same thing for DOS, Windows, VMS, UNIX of all kinds, : MVS, and more. This package provides an SMB/CIFS server that can be : used to provide network services to SMB/CIFS clients. : Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT : need the NetBEUI (Microsoft Raw NetBIOS frame) protocol. smb服务信息块协议用于共享文件,cifs通用网络文件系统 [root@centos ~]# yum install samba [root@centos ~]# rpm -ql samba /etc/logrotate.d/samba /etc/openldap/schema /etc/openldap/schema/samba.schema /etc/pam.d/samba /etc/rc.d/init.d/nmb /etc/rc.d/init.d/smb /etc/samba/smbusers /usr/sbin/nmbd /usr/sbin/smbd ........ [root@centos ~]# rpm -ql samba-client /usr/bin/findsmb /usr/bin/nmblookup /usr/bin/rpcclient /usr/bin/sharesec /usr/bin/smbcacls /usr/bin/smbclient /usr/bin/smbget /usr/bin/smbprint /usr/bin/smbspool /usr/bin/smbta-util /usr/bin/smbtar /usr/bin/smbtree ........ [root@centos ~]# echo "gentoo" | passwd --stdin gentoo [root@centos ~]# echo "centos" | passwd --stdin centos [root@centos ~]# echo "ubuntu" | passwd --stdin ubuntu [root@centos ~]# smbpasswd --help [root@centos ~]# groupadd develop [root@centos ~]# useradd -s /sbin/nologin -G develop gentoo [root@centos ~]# useradd -s /sbin/nologin -G develop centos [root@centos ~]# useradd -s /sbin/nologin ubuntu [root@centos ~]# smbpasswd -a gentoo New SMB password: Retype new SMB password: Added user gentoo. [root@centos ~]# smbpasswd -a centos New SMB password: Retype new SMB password: Added user centos. [root@centos ~]# smbpasswd -a ubuntu New SMB password: Retype new SMB password: Added user ubuntu. [root@centos ~]# smbpasswd -a hehe 使用smbpasswd添加samba用户的前提是用户在系统上必须存在 New SMB password: Retype new SMB password: Failed to add entry for user hehe. [root@centos ~]# ls -dlh /data/ 创建要共享的目录,并赋予系统用户相应权限 drwxr-xr-x. 2 root root 4.0K Jun 16 13:25 /data/ [root@centos ~]# chmod g+w /data/ && chown :develop /data/ [root@centos ~]# vim /etc/samba/smb.conf #======================= Global Settings ===================================== [global] 全局配置 workgroup = magedu server string = Samba Server Version %v netbios name = MYSERVER hosts allow = 192.168.40.0/24 # ----------------------- Standalone Server Options ------------------------ security = user 用户工作模式 passdb backend = tdbsam #============================ Share Definitions ============================== [shared] 共享名,共享设置 comment = Just for test path = /data public = no valid users = gentoo,centos,ubuntu,@develop read list = ubuntu write list = @develop writable = yes printable = no [root@centos ~]# setenforce 0 要关闭selinux,或者修改smb.conf中提示到的selinux布尔值 [root@centos ~]# service smb start Starting SMB services: tcp139 445 [ OK ] [root@centos ~]# service nmb start udp137 138 Starting NMB services: [ OK ] [root@centos ~]# smbclient //192.168.40.128/shared -U gentoo Enter gentoo's password: Domain=[MAGEDU] OS=[Unix] Server=[Samba 3.6.23-35.el6_8] smb: \> mkdir gentoo smb: \> ls . D 0 Fri Jun 17 15:09:44 2016 .. DR 0 Fri Jun 17 14:45:45 2016 gentoo D 0 Fri Jun 17 15:09:44 2016 51930 blocks of size 262144. 19439 blocks available smb: \> exit [root@centos ~]# smbclient //192.168.40.128/shared -U centos Enter centos's password: Domain=[MAGEDU] OS=[Unix] Server=[Samba 3.6.23-35.el6_8] smb: \> mkdir centos smb: \> ls . D 0 Fri Jun 17 15:10:11 2016 .. DR 0 Fri Jun 17 14:45:45 2016 gentoo D 0 Fri Jun 17 15:09:44 2016 centos D 0 Fri Jun 17 15:10:11 2016 51930 blocks of size 262144. 19439 blocks available smb: \> exit [root@centos ~]# smbclient //192.168.40.128/shared -U ubuntu Enter ubuntu's password: Domain=[MAGEDU] OS=[Unix] Server=[Samba 3.6.23-35.el6_8] smb: \> mkdir ubuntu NT_STATUS_MEDIA_WRITE_PROTECTED making remote directory \ubuntu smb: \>
2、搭建一套文件vsftp文件共享服务,共享目录为/ftproot,要求:(描述完整的过程)
1)基于虚拟用户的访问形式;
2)匿名用户只允许下载,不允许上传;
3)禁锢所有的用户于其家目录当中;
4)限制最大并发连接数为200:;
5)匿名用户的最大传输速率512KB/s
6)虚拟用户的账号存储在mysql数据库当中。
7)数据库通过NFS进行共享。
-
基于虚拟用户的vsftp
[root@centos ~]# yum install vsftpd mysql-server mysql pam_mysql -y 其中pam_mysql是由epel源提供 [root@centos ~]# rpm -ql vsftpd /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/rc.d/init.d/vsftpd /etc/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd_conf_migrate.sh /usr/sbin/vsftpd /usr/share/doc/vsftpd-2.2.2/EXAMPLE 可以参考其中的配置文件 /var/ftp /var/ftp/pub ........ [root@centos ~]# rpm -ql pam_mysql /lib64/security/pam_mysql.so ........ [root@centos ~]# ls /usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS* 配置ftp虚拟账户样例和指导 /usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS: logins.txt README README.configuration vsftpd.conf vsftpd.pam /usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS_2: README [root@centos ~]# service mysqld start mysql> create database vsftpd; 创建用于虚拟账号认证的数据库,表,用户,插入vsftp虚拟用户 Query OK, 1 row affected (0.00 sec) mysql> grant select on vsftpd.* to vsftpd@localhost identified by 'centos'; Query OK, 0 rows affected (0.00 sec) mysql> grant select on vsftpd.* to vsftpd@127.0.0.1 identified by 'centos'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> create table users(id int auto_increment not null,name char(20) not null,password char(50) binary not null,primary key(id)); Query OK, 0 rows affected (0.02 sec) mysql> insert into users(name,password) values('gentoo',password('gentoo')); Query OK, 1 row affected (0.00 sec) mysql> insert into users(name,password) values('ubuntu',password('ubuntu')); Query OK, 1 row affected (0.00 sec) [root@centos ~]# useradd -s /sbin/nologin -d /ftproot vuser [root@centos ~]# chmod go+rx /ftproot/ [root@centos ~]# cp /etc/vsftpd/vsftpd.conf{,.bak} [root@centos ~]# cd /etc/vsftpd/ [root@centos vsftpd]# ls ftpusers user_list vsftpd.conf vsftpd.conf.bak vsftpd_conf_migrate.sh [root@centos vsftpd]# cp /usr/share/doc/vsftpd-2.2.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf ./ cp: overwrite `./vsftpd.conf'? y [root@centos vsftpd]# cat vsftpd.conf anonymous_enable=NO local_enable=YES write_enable=NO anon_upload_enable=NO anon_mkdir_write_enable=NO anon_other_write_enable=NO chroot_local_user=YES 将用户禁锢在自己的家目录中 guest_enable=YES guest_username=vuser 指明虚拟用户映射到的系统用户 listen=YES pasv_min_port=30000 pasv_max_port=30999 pam_service_name=vsftpd.mysql 指明使用/etc/pam.d/vsftpd.mysql 来认证 [root@centos vsftpd]# cat /etc/pam.d/vsftpd.mysql #%PAM-1.0 auth required /lib64/security/pam_mysql.so user=vsftpd passwd=centos host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 account required /lib64/security/pam_mysql.so user=vsftpd passwd=centos host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2 上述为2行 crypt=0:明文密码 crypt=1:使用 crpyt()函数(对应 SQL 数据里的 encrypt(),encrypt()随机产生 salt) crypt=2:使用 MYSQL 中的 password()函数加密 crypt=3:表示使用 md5 的散列方式 [root@centos vsftpd]# service vsftpd start Starting vsftpd for vsftpd: [ OK ] [root@centos vsftpd]# yum install ftp -y [root@centos vsftpd]# ftp 127.0.0.1 Connected to 127.0.0.1 (127.0.0.1). 220 (vsFTPd 2.2.2) Name (127.0.0.1:root): gentoo 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files [root@centos vsftpd]# ftp 127.0.0.1 Connected to 127.0.0.1 (127.0.0.1). 220 (vsFTPd 2.2.2) Name (127.0.0.1:root): ubuntu 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files.
-
基于匿名用户的vsftp
[root@centos vsftpd]# grep -v "^#" vsftpd.conf anonymous_enable=YES 启用匿名用户访问 local_enable=NO write_enable=NO dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES download_enable=YES 允许下载 max_clients=50 最大并发客户端数目 anon_max_rate=512k 最大下载速率 pam_service_name=vsftpd userlist_enable=YES 针对系统用户访问的控制策略 tcp_wrappers=YES [root@centos pub]# ftp 127.0.0.1 Connected to 127.0.0.1 (127.0.0.1). 220 (vsFTPd 2.2.2) Name (127.0.0.1:root): anonymous 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> mkdir test 550 Permission denied. ftp> mget index.html mget index.html? y 227 Entering Passive Mode (127,0,0,1,80,144). 150 Opening BINARY mode data connection for index.html (0 bytes). 226 Transfer complete. 匿名用户vsftp的默认根目录为 /var/ftp/ 更多指令请man vsftpd.conf
原创文章,作者:Snoo,如若转载,请注明出处:http://www.178linux.com/37275
评论列表(1条)
配置很清晰,如要能将配置过程中出现的问题在此列举一二就更好了