####################################linux
#######第七單元.訪問網絡文件系統########vim
####################################windows
##########1.cifs網絡文件系統訪問#####bash
1.安裝共享訪問客戶端服務器
yum install samba-client -y網絡
2.識別共享服務器共享目錄less
smbclient -L //172.25.254.250dom
例如:[root@localhost ~]# smbclient -L //172.25.254.250ssh
Enter root's password: ##直接回車ide
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: cla***oom.example.com___________________ │
│ Base DN: dc=example,dc=com_______________________ │
│ │
│ ┌──────┐ ┌──────┐ │
│ │ Back │ │ Next │ │
│ └──────┘ └──────┘ │
│ │
│ │
└───────────────────────────────────────────────────┘
┌─────────────────┤ Kerberos Settings ├──────────────────┐
│ │
│ Realm: EXAMPLE.COM_____________________________ │
│ KDC: cla***oom.example.com___________________ │
│ Admin Server: cla***oom.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="cla***oom.example.com" \
--ldapbasedn="dc=example,dc=com" \
--krb5realm="EXAMPLE.COM" \
--krb5kdc="cla***oom.example.com" \
--krb5adminserver="cla***oom.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
在此文件中設定配置文件中的全部參數,此文件的優先級搞