马哥教育网络班21期+第13周课程练习

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

赞 (0)
SnooSnoo
上一篇 2016-08-24 21:23
下一篇 2016-08-24 21:23

相关推荐

  • Linux基础–命令帮助的获取及history历史命令

    第一部分    Linux系统如何获取命令帮助     1、命令类型以及简单帮助的获取         linux系统上,基本命令分为两类,一类是内建命令,一类是外部命令。所谓内建命令,是指由linux内核自带的系统命令…

    Linux干货 2016-07-28
  • 马哥教育网络班21期+第11周课程练习

    1、请描述一次完整的加密通讯过程,结合图示最佳。 Bob先利用单向加密算法提取当前数据的指纹(特征码),再用自己的私钥加密数据指纹并附加于数据尾部,然后利用对称加密将整个文件加密,之后用对方的公钥加密对称加密密钥附加于尾部。 Alice收到数据后,先用自己的私钥解密,得到对称加密密钥,之后用对称加密密钥解密,然后用Bob的公钥解密得到数据指纹,并且验证了Bo…

    Linux干货 2016-09-26
  • linux中find命令的那些事

         概述:在介绍find这个强大的文件查找命令前,我们先介绍两个较简单的文件查找命令whereis和locate命令,通常我们都是先使用whereis或者是locate检查,如果真的找不到了,才用find来查找,因为whereis和locate是利用数据库来查找数据的,速度相当快,节约时间,缺点就是有可…

    Linux干货 2016-08-18
  • Linux磁盘管理命令

    Linux有着管理各种存储设备的强大能力。Linux把所有磁盘都当作文件管理,从而简化我们对其进行的读写等操作。 IDE接口的硬盘在Linux中命名为:/dev/hd{a|b|c……},比如/dev/hda; 其他硬盘比如SATA接口的硬盘命名为:/dev/sd{a|b|c……},比如/dev/sda。 注:{…

    Linux干货 2015-12-06
  • 安装LNMP + 搭建WordPress个人博客

    安装LNMP + 搭建Wordpress个人博客 前言 来到马哥教育也有几个月了,学了很多知识。现在想要把这些知识能够存储在一个地方,随时随地的都能看到,于是乎我就想到了博客,以下我搭建Wordpress的过程。 安装LNMP 一、关掉防火墙 # chkconfig iptables off 二、安装开发包和库文件 #&nbsp…

    Linux干货 2016-05-31
  • MogileFS基于Nginx反向代理实现分布式存储与访问

    前言 随着信息社会的发展,越来越多的信息被数据化,尤其是伴随着大数据时代的来临,数据呈爆炸式增长。传统存储在面对海量数据存储表现出的力不从心已经是不争的事实,例如:纵向扩展受阵列空间限制,横向扩展受交换设备限制,节点受文件系统限制等。而分布式存储的出现在一定程度上有效的缓解了这一问题,目前比较流行的分布式文件系统有:GFS、HDFS、GlusterFS、Mo…

    Linux干货 2015-07-08

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-30 13:30

    配置很清晰,如要能将配置过程中出现的问题在此列举一二就更好了