####################################

#######第七单元.访问网络文件系统########

####################################



##########1.cifs网络文件系统访问#####


1.安装共享访问客户端

yum install samba-client -y


2.识别共享服务器共享目录

smbclient -L //172.25.254.250


例如:[root@localhost ~]# smbclient -L //172.25.254.250

Enter root's password: ##直接回车

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]


Sharename       Type      Comment

---------       ----      -------

westos1         Disk      test share

westos2         Disk      test share

westos3         Disk      test share

westos4         Disk      test share

IPC$            IPC       IPC Service (Samba Server Version 4.1.1)

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment

---------            -------

Workgroup            Master

---------            -------


3.访问共享

命令访问)

例如:[root@localhost ~]# smbclient //172.25.254.250/westos1

Enter root's password: ##直接回车

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb:\>


挂载访问)

mount //172.25.254.250/westos /mnt -o username=guest


4.开机自动挂载

方法一:

vim /etc/fstab

//172.25.254.250/westos /mnt cifs defaults,username=guest 0 0


方法二:

vim /etc/rc.d/rc.local

mount //172.25.254.250/westos /mnt -o username=guest



#######2.nfs网络文件系统的访问#####


1.安装访问共享软件

yum install nfs-utils -y


2.识别共享

showmount -e 172.25.254.250


3.使用共享

mount 172.25.254.250:/nfsshare/nfs1 /mnt


4.自动挂载

方法一:

vim /etc/fstab

172.25.254.250:/nfsshare/nfs1 /mnt nfs defaults 0 0


方法二:

vim /etc/rc.d/rc.local

mount 172.25.254.250:/nfsshare/nfs1  /mnt

保存退出后执行:

chmod 755 /etc/rc.d/rc.local


######autofs自动挂载服务#####

1.服务功能

默认使用mount挂载共享时当不使用共享也会处于挂载状态

浪费共享服务资源

autofs可以实现当使用时自动挂载,当闲置时自动卸载


2.安装服务

yum install autofs -y

systemctl start autofs


3.访问

cd /net/172.25.254.250/nfsshare/nfs1


4.设定卸载时间

vim /etc/autofs.conf

15 timeout = 3 ##闲置3秒后系统自动卸载网络设备

重启服务后生效


实例:

[root@localhost ~]# yum install autofs -y

[root@localhost ~]# systemctl start autofs

[root@localhost ~]# cd /net

[root@localhost net]# ls

[root@localhost net]# cd 172.25.254.250

[root@localhost 172.25.254.250]# cd nfsshare/nfs2

[root@localhost nfs2]# df

Filesystem                    1K-blocks     Used Available Use% Mounted on

/dev/vda1                      10473900  3813364   6660536  37% /

devtmpfs                         927072        0    927072   0% /dev

tmpfs                            942660      140    942520   1% /dev/shm

tmpfs                            942660    17036    925624   2% /run

tmpfs                            942660        0    942660   0% /sys/fs/cgroup

172.25.254.250:/nfsshare/nfs2 100221952 71805952  28416000  72% /net/172.25.254.250/nfsshare/nfs2

[root@localhost nfs2]# vim /etc/autofs.conf ##在15行 timeout = 3

[root@localhost nfs2]# systemctl restart auto.service

[root@localhost nfs2]# touch we

[root@localhost nfs2]# ls

file  file1  file2  file3  file4  file5  we

[root@localhost nfs2]# df

Filesystem                    1K-blocks     Used Available Use% Mounted on

/dev/vda1                      10473900  3813364   6660536  37% /

devtmpfs                         927072        0    927072   0% /dev

tmpfs                            942660      140    942520   1% /dev/shm

tmpfs                            942660    17036    925624   2% /run

tmpfs                            942660        0    942660   0% /sys/fs/cgroup

172.25.254.250:/nfsshare/nfs2 100221952 71805952  28416000  72% /net/172.25.254.250/nfsshare/nfs2

[root@localhost nfs2]# cd ##等待三秒,然后执行下一条语句

[root@localhost ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3813364   6660536  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660     140    942520   1% /dev/shm

tmpfs             942660   17036    925624   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup


5.实现自定义共享挂载点

vim /etc/auto.master

最终自定义挂载点的上层目录  子配置文件

/mnt /etc/auto.nfs

systemctl restart auto


vim  /子配置文件

vim  /etc/auto.nfs

pub1 172.25.254.250:/nfsshare/nfs1

* 172.25.254.250:/nfsshare/& ##指定任意共享挂载


实例:

[root@localhost ~]# vim /etc/auto.master

[root@localhost ~]# vim /etc/auto.nfs ##此处文件内容为: pub1 172.25.254.250:/nfsshare/nfs1

[root@localhost ~]# cd /mnt

[root@localhost mnt]# ls

[root@localhost mnt]# cd pub1

-bash: cd: pub1: No such file or directory

[root@localhost mnt]# systemctl restart autofs.service 

[root@localhost mnt]# cd /mnt

[root@localhost mnt]# cd pub1

[root@localhost pub1]# ls

1           file1    file3  file6  file9   XX

[root@localhost pub1]# df

Filesystem                    1K-blocks     Used Available Use% Mounted on

/dev/vda1                      10473900  3813392   6660508  37% /

devtmpfs                         927072        0    927072   0% /dev

tmpfs                            942660      140    942520   1% /dev/shm

tmpfs                            942660    17036    925624   2% /run

tmpfs                            942660        0    942660   0% /sys/fs/cgroup

172.25.254.250:/nfsshare/nfs1 100221952 71805952  28416000  72% /mnt/pub1

[root@localhost ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3813372   6660528  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660     140    942520   1% /dev/shm

tmpfs             942660   17036    925624   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

[root@localhost ~]# vim /etc/auto.nfs ##此处文件内容为: * 172.25.254.250:/nfsshare/&

[root@localhost ~]# cd /mnt/nfs2

[root@localhost nfs2]# df

Filesystem                    1K-blocks     Used Available Use% Mounted on

/dev/vda1                      10473900  3813396   6660504  37% /

devtmpfs                         927072        0    927072   0% /dev

tmpfs                            942660      140    942520   1% /dev/shm

tmpfs                            942660    17036    925624   2% /run

tmpfs                            942660        0    942660   0% /sys/fs/cgroup

172.25.254.250:/nfsshare/nfs2 100221952 71812096  28409856  72% /mnt/nfs2

[root@localhost ~]# cd

[root@localhost ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3813376   6660524  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660     140    942520   1% /dev/shm

tmpfs             942660   17036    925624   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup




################################

#######第八单元.ldap网络帐号#######

################################

1.ldap是什么

ldap目录服务认证,和windows活动目录类似,就是记录数据的一种方式


2.ldap客户端所须软件

yum install sssd krb5-workstation -y


3.如何开启ldap用户认证

authconfig-tui


┌────────────────┤ Authentication Configuration ├─────────────────┐

│                                                                 │ 

│  User Information        Authentication                         │ 

│  [ ] Cache Information   [ ] Use MD5 Passwords                  │ 

│  [*] Use LDAP            [*] Use Shadow Passwords               │ 

│  [ ] Use NIS             [ ] Use LDAP Authentication            │ 

│  [ ] Use IPAv2           [*] Use Kerberos                       │ 

│  [ ] Use Winbind         [ ] Use Fingerprint reader             │ 

│                          [ ] Use Winbind Authentication         │ 

│                          [*] Local authorization is sufficient  │ 

│                                                                 │ 

│            ┌────────┐                      ┌──────┐             │ 

│            │ Cancel │                      │ Next │             │ 

│            └────────┘                      └──────┘             │ 

│                                                                 │ 

│                                                                 │ 

└─────────────────────────────────────────────────────────────────┘ 

                                                                                           



┌─────────────────┤ LDAP Settings ├─────────────────┐

│                                                   │ 

│          [*] Use TLS                              │ 

│  Server: classroom.example.com___________________ │

│ Base DN: dc=example,dc=com_______________________ │ 

│                                                   │ 

│         ┌──────┐                ┌──────┐          │ 

│         │ Back │                │ Next │          │ 

│         └──────┘                └──────┘          │ 

│                                                   │ 

│                                                   │ 

└───────────────────────────────────────────────────┘ 

                                                      




┌─────────────────┤ Kerberos Settings ├──────────────────┐

│                                                        │ 

│        Realm: EXAMPLE.COM_____________________________ │ 

│          KDC: classroom.example.com___________________ │ 

│ Admin Server: classroom.example.com___________________ │ 

│               [ ] Use DNS to resolve hosts to realms   │ 

│               [ ] Use DNS to locate KDCs for realms    │ 

│                                                        │ 

│          ┌──────┐                    ┌────┐            │ 

│          │ Back │                    │ Ok │            │ 

│          └──────┘                    └────┘            │ 

│                                                        │ 

│                                                        │ 

└────────────────────────────────────────────────────────┘ 

                                                          

<当出现以下报错时>


┌────────────────┤ Warning ├─────────────────┐

│                                            │ 

│ To connect to a LDAP server with TLS       │ 

│ protocol enabled you need a CA certificate │ 

│ which signed your server's certificate.    │ 

│ Copy the certificate in the PEM format to  │ 

│ the '/etc/openldap/cacerts' directory.     │ 

│ Then press OK.                             │ 

│                                            │ 

│                  ┌────┐                    │ 

│                  │ Ok │                    │ 

│                  └────┘                    │ 

│                                            │ 

│                                            │ 

└────────────────────────────────────────────┘ 

                                                                                

时因为tls的证书缺失,需要到服务器端下载所需要的证书到/etc/openldap/cacerts,

用到的命令

wget http://172.25.254.254/pub/example-ca.crt

然后执行:

authconfig-tui


┌────────────────┤ Authentication Configuration ├─────────────────┐

│                                                                 │ 

│  User Information        Authentication                         │ 

│  [ ] Cache Information   [ ] Use MD5 Passwords                  │ 

│  [ ] Use LDAP            [*] Use Shadow Passwords               │ 

│  [ ] Use NIS             [ ] Use LDAP Authentication            │ 

│  [ ] Use IPAv2           [ ] Use Kerberos                       │ 

│  [ ] Use Winbind         [ ] Use Fingerprint reader             │ 

│                          [ ] Use Winbind Authentication         │ 

│                          [*] Local authorization is sufficient  │ 

│                                                                 │ 

│            ┌────────┐                      ┌──────┐             │ 

│            │ Cancel │                      │ Next │             │ 

│            └────────┘                      └──────┘             │ 

│                                                                 │ 

│                                                                 │ 

└─────────────────────────────────────────────────────────────────┘ 


然后再次执行:

authconfig-tui 

┌────────────────┤ Authentication Configuration ├─────────────────┐

│                                                                 │ 

│  User Information        Authentication                         │ 

│  [ ] Cache Information   [ ] Use MD5 Passwords                  │ 

│  [*] Use LDAP            [*] Use Shadow Passwords               │ 

│  [ ] Use NIS             [ ] Use LDAP Authentication            │ 

│  [ ] Use IPAv2           [*] Use Kerberos                       │ 

│  [ ] Use Winbind         [ ] Use Fingerprint reader             │ 

│                          [ ] Use Winbind Authentication         │ 

│                          [*] Local authorization is sufficient  │ 

│                                                                 │ 

│            ┌────────┐                      ┌──────┐             │ 

│            │ Cancel │                      │ Next │             │ 

│            └────────┘                      └──────┘             │ 

│                                                                 │ 

│                                                                 │ 

└─────────────────────────────────────────────────────────────────┘ 

                                                                                                                

然后一直按 next 至 ok 即可。


<测试> 

getent passwd ldapuser1

如果用户信息可以正常显示,证明客户端认成功。


列出所有用户

vim /etc/sssd/sssd.conf

enumerate = True ##在第一个[domain/default]版块中写入,即写在第16行

systemctl restart sssd


4.自动挂载用户家目录(若用户家目录配置错误,则用图形页面登录后黑屏,然后返回至登录页面)

yum install autofs -y

vim /etc/auto.master

/home/guests /etc/auto.ldap ##在第14行写入


vim /etc/auto.ldap

ldapuser1 172.25.254.254:/home/guests/ldapuser1 ##单个对应用户可用

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

* 172.25.254.254:/home/guests/& ##全部用户可用


systemctl restart autofs                                

systemctl enable autofs


脚本执行(脚本内容如下):

#!/bin/bash

echo "install software ing..."

yum install sssd krb5-workstation autofs -y &> /dev/null


echo "config ldap auth client ing..."


authconfig \ ##以下全为配置参数(和3中的框图对应)

--enableldap \

--enablekrb5 \

--disableldapauth \ ##此处表示不开启ldap自己的权限(密码)

--enableldaptls \

--ldaploadcacert=http://172.25.254.254/pub/example-ca.crt \

--ldapserver="classroom.example.com" \

--ldapbasedn="dc=example,dc=com" \

--krb5realm="EXAMPLE.COM" \

--krb5kdc="classroom.example.com" \

--krb5adminserver="classroom.example.com" \

--enablesssd \

--enablesssdauth \

--update


echo "config ldap user\'s home directory ing..."

echo /home/guests /etc/auto.ldap >> /etc/auto.master

echo "*         172.25.254.254:/home/guests/&" >> /etc/auto.ldap

systemctl restart autofs

systemctl enable autofs &> /dev/null


echo " all is sucessfully !!!"

以上为脚本内容!!!

@@@!!!对脚本中的配置参数不清楚时可以使用下面的命令进行查看,命令为:

authconfig --help | less 


测试:

先对server主机进行reset操作

在server主机中的/mnt目录下编写此脚本,文件名为set-ldap.sh

然后执行命令:sh set-ldap.sh

(退出当前用户,使用服务器用户登录)/(直接执行su - 服务器用户)进行登录验证




##############################

#######第九单元.ftp服务#########

##############################


1.ftp的定义:

FTP ( 文件传输协议 ) 是 INTERNET 上仍常用的最老的网络协议之一 , 它为系统提供了通过网络与远程服务器进行传输的简单方法

在 RED HAT ENTREPRISE LINUX 6 中。 FTP 服务器包的名称为 VSFTPD , 它代表 Very Secure File TransferProtocol Damon 服务器名称也叫做 vsftpd

默认配置文件让 ANONYMOUS 用户只能下载位于CHROOT 目录中的内容。 /var/ftp/ 这意味着远程 FTP客户端能以用户 anonymous 或 ftp 身份连接到服务器( 无需密码 ), 

并从 ftp 服务器上的 /var/ftp/ 目录下载文件( 其本地 ftp 用户可以读取这些文件 )


2.安装ftp

yum install vsftpd -y ##安装软件

systemctl start vsftpd ##启动软件服务

firewall-cmd --list-all ##查看火墙中允许的服务

firewall-cmd --permanent --add-service=ftp ##将ftp服务添加到火墙允许的服务行列中

firewall-cmd --reload ##重新读取火墙允许服务配置

firewall-cmd --list-all ##再次查看火墙中允许的服务


实例:

[root@desktop7 ~]# yum install vsftpd -y 

Installed:

  vsftpd.x86_64 0:3.0.2-10.el7                                        


Complete!

[root@desktop7 ~]# systemctl start vsftpd

[root@desktop7 ~]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources: 

  services: dhcpv6-client ssh

  ports: 

  masquerade: no

  forward-ports: 

[root@desktop7 ~]# firewall-cmd --permanent --add-service=ftp

success

[root@desktop7 ~]# firewall-cmd --reload

success

[root@desktop7 ~]# firewall-cmd --list-all

public (default, active)

  interfaces: eth0

  sources: 

  services: dhcpv6-client ftp ssh

  ports: 

  masquerade: no


3.vsftp文件信息

/var/ftp ##默认发布目录

/etc/vsftpd ##配置目录


4.vsftpd服务的配置参数


1)匿名用户设定


anonymous_enable=YES|NO ##匿名用户登录限制


实例:

 11 # Allow anonymous FTP? (Beware - allowed by default if you comment this out).

 12 anonymous_enable=YES

 13 #


@@@!!!作此操作实验时,用真机执行:(相当于监控命令)

lftp 172.25.7.10

cd pub/


@@@!!!切记:执行以下操作,每次修改配置文件后,都需要重启服务 

即执行:systemctl restart vsftpd



<匿名用户上传>

vim /etc/vsftpd/vsftpd.conf

将文件中:

write_enable=YES

anon_upload_enable=YES

然后:

systemctl restart vsftpd

setenforce 0 ##将selinux调整成警告模式,使其不能阻止访问

chgrp ftp /var/ftp/pub

chmod 775 /var/ftp/pub



<匿名用户加目录修改>

anon_root=/dir

例如:

anon_root=/home



<匿名用户上传文件默认权限修改>

anon_umask=xxx

例如:

anon_umask=022



<匿名用户建立目录>

anon_mkdir_write_enable=YES|NO



<匿名用户下载>

anon_world_readable_only=YES|NO ##设定参数值为no表示匿名用户可以下载文件



<匿名用户删除>

anon_other_write_enable=YES|NO



<匿名用户使用的用户身份修改>

chown_uploads=YES

chown_username=student



<最大上传速率>

anon_max_rate=102400


#<最大链接数>

max_clients=2



2)本地用户设定

local_enable=YES|NO ##本地用户登陆限制

write_enable=YES|NO ##本地用户写权限限制



#<本地用户家目录修改>

local_root=/directory



#<本地用户上传文件权限>

local_umask=xxx



#<限制本地用户浏览/目录>

所有用户被锁定到自己的家目录中

chroot_local_user=YES

chmod u-w /home/*



#<用户黑名单建立>

chroot_local_user=NO

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/chroot_list



#<用户白名单建立>

chroot_local_user=YES

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/chroot_list


!!!@@@要注意白名单和黑名单的不同仅为:chroot_local_user=NO


#<限制本地用户登陆>

vim /etc/vsftpd/ftpusers ##用户黑名单

vim /etc/vsftpd/user_list ##用户临时黑名单


[root@server7 ~]# cd /etc/vsftpd/

[root@server7 vsftpd]# ls

chroot_list  ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh

此目录下ftpusers的优先级最高,在ftpusers中的用户永远不能使用ftp服务

user_list优先级比ftpusers低.


#<用户白名单设定>

userlist_deny=NO ##在倒数第二行处添加

/etc/vsftpd/user_list ##参数设定,此文件变成用户白名单,只在名单中出现的用户可以登陆ftp



#<ftp虚拟用户的设定>

创建虚拟帐号身份)

vim /etc/vsftpd/loginusers ##文件名称任意

ftpuser1

123

ftpuser2

123

ftpuser3

123


db_load -T -t hash -f /etc/vsftpd/loginusers loginusers.db

-T ##表示转化

-t ##表示转化成为的格式(即,加密的格式)

-f ##后面紧接要转化的文件,再接转化成为的文件


vim /etc/pam.d/ckvsftpd ##文件名称任意

account required pam_userdb.so db=/etc/vsftpd/loginusers

auth required pam_userdb.so db=/etc/vsftpd/loginusers


vim /etc/vsftpd/vsftpd.conf

在文件末尾修改内容为:

pam_service_name=ckvsftpd ##此处文件为/etc/pam.d/ 目录下自己所建立的文件

guest_enable=YES

guest_username=ftpuser ##虚拟帐号身份指定

然后:

chmod u-w /home/ftpuser (此条语句 执行/不执行 都可以)


虚拟帐号家目录独立设定)

vim /etc/vsftpd/vsftpd.conf

local_root=/ftpuserhome/$USER

user_sub_token=$USER


mkdir /ftpuserhome

chgrp ftpuser /ftpuserhome

chmod g+s /ftpuserhome

mkdir /ftpuserhome/ftpuser{1..3}


实例:

[root@server7 vsftpd]# mkdir /ftpdir/lzt1 -p

[root@server7 vsftpd]# mkdir /ftpdir/lzt2 -p

[root@server7 vsftpd]# mkdir /ftpdir/lzt3 -p

[root@server7 vsftpd]# touch /ftpdir/lzt1/lzt1file

[root@server7 vsftpd]# touch /ftpdir/lzt2/lzt2file

[root@server7 vsftpd]# touch /ftpdir/lzt3/lzt3file

[root@server7 vsftpd]# vim /etc/vsftpd/vsftpd.conf 

[root@server7 vsftpd]# systemctl restart vsftpd.service 

[root@server7 vsftpd]# lftp 172.25.7.11 -u lzt1

Password: 

lftp lzt1@172.25.7.11:~> ls         

-rw-r--r--    1 0        0               0 Nov 13 07:44 lzt1file

lftp lzt1@172.25.7.11:/> quit

[root@server7 vsftpd]# lftp 172.25.7.11 -u lzt2

Password: 

lftp lzt2@172.25.7.11:~> ls         

-rw-r--r--    1 0        0               0 Nov 13 07:44 lzt2file

lftp lzt2@172.25.7.11:/> quit



虚拟帐号配置独立)

vim /etc/vsftpd/vsftpd.conf

user_config_dir=/etc/vsftpd/userconf

mkdir -p /etc/vsftpd/userconf


vim /etc/vsftpd/userconf/ftpuser1

在此文件中设定配置文件中的所有参数,此文件的优先级搞