马哥教育网络班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
下一篇 2016-08-24

相关推荐

  • Linux-raid的工作原理与管理

    本章内容:        1、RAID详细描述        2、mdadm 工具        3、创建raid        4、磁盘阵列的管理 RAID描述:     &nb…

    2017-06-24
  • 马哥教育网络班21期-第十周课程练习​

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情)流程顺序:POST(加电自检) –> BootSequence (BIOS) –> Bootloader(MBR) –> kernel(ramdisk) –> rootfs(只读方式) –> sw…

    Linux干货 2016-09-26
  • 6.vim编辑器使用方法总结

    vi: visual interface,文本编辑器 vim: vi improved,vi的增强版 文本:ASCII,Unicode, 文本编辑器种类: 行编辑器:sed, 全屏编辑器:nano,vi vim:模式化的编辑器 基本模式: 编辑模式,也叫命令模式 输入模式 末行模式:内置的命令行接口 模式转换: 编辑模…

    Linux干货 2017-08-06
  • 马哥linux0726课程内容

    课堂内容笔记   使用几个符号可以使用原始命令 \,’’,绝对路径运行 这三种方法都可以使用到原始命令,不使用别名   别名-内部命令-缓存-外部命令 使用命令的优先级   man帮助具体用法 makewhatis老版本安装whatis mandb新版本安装whatis man的具体路径在/usr/share/man whati…

    Linux干货 2016-08-04
  • linux高级文件系统管理

    磁盘配额:         (1)如果存放的文件空间不足,虽然分区后不能直接扩容,但是可以迁移,下面以/home目录示例: 1、新建分区,同步分区表 /dev/sda62、mkfs.ext4 /dev/sda6             &n…

    Linux干货 2017-03-14
  • LVM 逻辑卷管理

    一、概述: LVM: logical Volumn Manager  LVM是建立在硬盘和分区之上的一个逻辑层。可以将多个物理分区整合起来,无需停机,可以对文件系统的大小进行调整。同时,还提供快照功能 二、概念及实现过程: PE :每一个物理卷PV被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的…

    Linux干货 2015-10-05

评论列表(1条)

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

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