馬哥教育網絡班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.www58058.com/37275

(0)
SnooSnoo
上一篇 2016-08-24
下一篇 2016-08-24

相關推薦

  • iptables 補充本

    淺談iptables一 什么是iptablesiptables 是工作在內核之上的netfilter框架的前端工具(iptables是netfilter的管理工具這樣說也不為過)Firewall:隔離工具,工作于主機或網絡的邊緣處,對經由的報文根據預先定義的規則(識別標準)進行檢測,對于能夠被規則匹配到的報文實行某種預定義的處理機制的一套組件; 硬…

    Linux干貨 2017-05-15
  • 進入linux世界的初步認識

    1、 描述計算機的組成及其功能.
    2、 按系列羅列Linux的發行版,并描述不同發行版之間的聯系與區別.
    3、 描述Linux的哲學思想,并按照自己的理解對其進行解釋性描述.
    4、 說明Linux系統上命令的使用格式;詳細介紹ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,并配合相應的示例來闡述.
    5、 如何在Linux系統上獲取命令的幫助信息,請詳細列出,并描述man文檔的章節是如何劃分的.
    6、 請羅列Linux發行版的基礎目錄名稱命名法則及功用規定.

    Linux干貨 2018-02-25
  • Linux的軟件包管理(RPM)

    軟件包管理(RPM)   本章節內容:   軟件運行環境   軟件包基礎  Rpm包管理   一、軟件運行環境(了解API和ABI)  API:應用程序開發接口,POSIX國際標準。  程序源代碼–> 預處理–> 編譯–&…

    Linux干貨 2016-08-21
  • 推薦-自動化運維之puppet小試牛刀

     一、puppet介紹       puppet是IT基礎設施自動化管理工具,“她”能夠幫助系統管理員管理基礎設施的整個生命周期:供應(provisioning、配置(configuration)、聯動(orchestration)及報告(reporting)。    …

    Linux干貨 2016-04-05
  • 馬哥linux2014|2015全套教程

    1、本課程全程將基于集成了Openstack云環境、支持高精度時間(PTP)及虛擬化性能大大提升的RHEL 6.5或CentOS 6.6,間或介紹CentOS 7系統的使用; 2、此文章給出的只是個課程知識點框架,實際講解過程相當精細;另外,知識點講授的次序未必同此文章所標示的順序相同; 3、第15期面授班定于2015年3月24號開課;本期將會是馬哥教育數年…

    Linux干貨 2015-07-14
  • N21天天第十二周課程練習

    1、請描述一次完整的http請求處理過程; 1、建立TCP連接 2、Web瀏覽器向Web服務器發送請求 3、Web瀏覽器發送請求頭信息   建立連接后,客戶機發送一個請求給服務器,請求方式的格式為:統一資源標識符(URL)、協議版本號,后邊是MIME   信息包括請求修飾符、客戶機信息和可能的內容 4、Web服務器應答…

    Linux干貨 2016-10-31

評論列表(1條)

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

    配置很清晰,如要能將配置過程中出現的問題在此列舉一二就更好了

欧美性久久久久