首页 > 代码库 > Linux课程第十五天学习笔记

Linux课程第十五天学习笔记

###############################
#######  访问网络文件系统    #######
###############################

Linux中有两种主要协议可用来访问网络文件系统:NFS和CIFS
NFS(Network File System)可看作是Linux、UNIX及其它类似操作系统的标准文件系统
CIFS(Comon Internet File System)则是针对Microsoft Windows系统的标准网络文件系统

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

####################
在windows 7下开启文件共享:
创建一个文件夹
右健点击“属性”,点击“共享”选项卡,点击“共享”
下拉列表选择“Everyone”,点击“添加”,选择“读/写”权限,点击“共享”,等待,点击“完成”
使用win+r调出运行窗口,输入“\\ip地址”测试
注意:
到这里还没有完,因为windows 7默认不启用“Guest”帐户,并且默认拒绝匿名用户的访问,所以还需要以下操作
1.打开“控制面板”,点击“添加或删除用户账户”,点击“Guest”帐户,点击“启用”
2.使用win+r调出运行窗口,输入“gpedit.msc”,打开本地组策略编辑器。依次选择“计算机配置-->Windows设置-->安全设置-->本地策略-->用户权限分配”,双击“拒绝从网络访问这台计算机”,删除里面的“Guest”帐号,点击“确定”。
(参考网址:https://zhidao.baidu.com/question/2052592758746862227.html)
####################

1.安装共享访问客户端
yum install samba-client -y

2.识别共享服务器共享目录
smbclient -L //172.25.254.253
[root@netfsclient mnt]# smbclient -L //172.25.254.253
直接回车

####################
[root@localhost ~]# smbclient -L //172.25.50.159        ##使用Guest用户
Enter root‘s password:
Domain=[TEST-PC] OS=[Windows 7 Ultimate 7600] Server=[Windows 7 Ultimate 6.1]

    Sharename       Type      Comment
    ---------       ----      -------
    ADMIN$          Disk      远程管理
    C$              Disk      默认共享
    D$              Disk      默认共享
    IPC$            IPC       远程 IPC
    Users           Disk      
    westos          Disk      
Connection to 172.25.50.159 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
NetBIOS over TCP disabled -- no workgroup available
[root@localhost ~]# smbclient -L //172.25.50.159 -U test%test    ##使用本地用户,"%"后面跟密码
Domain=[TEST-PC] OS=[Windows 7 Ultimate 7600] Server=[Windows 7 Ultimate 6.1]

    Sharename       Type      Comment
    ---------       ----      -------
    ADMIN$          Disk      远程管理
    C$              Disk      默认共享
    D$              Disk      默认共享
    IPC$            IPC       远程 IPC
    Users           Disk      
    westos          Disk      
Connection to 172.25.50.159 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
NetBIOS over TCP disabled -- no workgroup available
####################

3.访问共享
命令访问)
[root@netfsclient mnt]# smbclient //172.25.254.253/westos

####################
[root@localhost ~]# smbclient //172.25.50.159/westos
Enter root‘s password:
Domain=[TEST-PC] OS=[Windows 7 Ultimate 7600] Server=[Windows 7 Ultimate 6.1]      
smb: \> pwd
Current directory is \\172.25.50.159\westos\
smb: \> ls
  .                                   D        0  Tue Nov 15 01:47:12 2016
  ..                                  D        0  Tue Nov 15 01:47:12 2016

        40864 blocks of size 131072. 40863 blocks available
smb: \> !ls
anaconda-ks.cfg  Documents  Music     Public     Videos
Desktop         Downloads  Pictures  Templates
smb: \> put anaconda-ks.cfg
putting file anaconda-ks.cfg as \anaconda-ks.cfg (25.9 kb/s) (average 25.9 kb/s)
smb: \> del anaconda-ks.cfg         ##等同于"rm anaconda-ks.cfg"

>在win7的westos共享文件夹中创建123.txt
smb: \> ls
  .                                       D        0  Tue Nov 15 01:47:12 2016
  ..                                      D        0  Tue Nov 15 01:47:12 2016
  123.txt                             A        0  Tue Nov 15 02:44:54 2016

        40864 blocks of size 131072. 40863 blocks available
smb: \> get 123.txt
getting file \123.txt of size 0 as 123.txt (0.0 KiloBytes/sec) (average 0.0 KiloBytes/sec)
smb: \> !ls
123.txt         Desktop    Downloads  Pictures  Templates
anaconda-ks.cfg  Documents  Music      Public     Videos
smb: \> exit
[root@localhost ~]#
####################

挂载访问)
mount //172.25.254.253/westos /mnt -o username=guest

####################
[root@localhost ~]# mount //172.25.254.253/westos /mnt
mount: wrong fs type, bad option, bad superblock on //172.25.254.253/westos,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
##失败原因是linux的匿名用户不是Guest
[root@localhost ~]# mount //172.25.50.159/westos /mnt -o username=guest
[root@localhost ~]# df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3157404   7316496  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996      80    508916   1% /dev/shm
tmpfs                     508996   13344    495652   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
//172.25.50.159/westos   5230592      16   5230576   1% /mnt
[root@localhost ~]# mount //172.25.50.159/westos /mnt -o username=guest
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
123.txt
[root@localhost mnt]# touch file{1..3}
[root@localhost mnt]# ls
123.txt  file1  file2  file3
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# ls
[root@localhost mnt]# cd
[root@localhost ~]# umount /mnt
####################

4.开机自动挂载cifs
方法1)
vim /etc/fstab
//172.25.254.253/westos /mnt    cifs    defaults,username=guest 0 0

####################
[root@localhost ~]# vim /etc/fstab
--------------------------------------------------
添加:
//172.25.50.159/westos  /mnt    cifs    defaults,username=guest 0 0
:wq
--------------------------------------------------
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3157452   7316448  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996      80    508916   1% /dev/shm
tmpfs                     508996   13372    495624   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
//172.25.50.159/westos   5230592      16   5230576   1% /mnt
####################

方法2)
vim /etc/rc.d/rc.local
mount //172.25.254.253/westos /mnt/ -o username=guest

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

建议写道rc.local,如果写到fstab,一旦写错就导致系统启不起来

####################
[root@localhost ~]# vim /etc/rc.d/rc.local
--------------------------------------------------
添加:
mount //172.25.50.159/westos /mnt/ -o username=guest
:wq
--------------------------------------------------
[root@localhost ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 2655 Nov 15 03:23 /etc/rc.d/rc.local
[root@localhost ~]# chmod 755 /etc/rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 2708 Nov 15 03:51 /etc/rc.d/rc.local
[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3157460   7316440  31% /
devtmpfs          493408       0    493408   0% /dev
tmpfs             508996      80    508916   1% /dev/shm
tmpfs             508996   13372    495624   3% /run
tmpfs             508996       0    508996   0% /sys/fs/cgroup
[root@localhost ~]# sh /etc/rc.d/rc.local
[root@localhost ~]# df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3157460   7316440  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996      80    508916   1% /dev/shm
tmpfs                     508996   13372    495624   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
//172.25.50.159/westos   5230592      16   5230576   1% /mnt
####################

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

nfs-utils客户端和服务端一样,类似chronyd

####################
服务端:
[root@localhost ~]# mkdir -p /nfsshare/nfs{1..5}
[root@localhost ~]# yum install nfs-utils -y
[root@localhost ~]# vim /etc/exports
--------------------------------------------------
/nfsshare/nfs1  *(rw,no_root_squash)
/nfsshare/nfs2  *(rw,no_root_squash)
/nfsshare/nfs3  *(rw,no_root_squash)
/nfsshare/nfs4  *(rw,no_root_squash)
/nfsshare/nfs5  *(rw,no_root_squash)
:wq
--------------------------------------------------
##"no_root_squash"表示不将root用户及所属用户组映射为匿名用户或匿名用户组,默认root是被映射为匿名用户的
[root@localhost ~]# exportfs -rv
exporting *:/nfsshare/nfs5
exporting *:/nfsshare/nfs4
exporting *:/nfsshare/nfs3
exporting *:/nfsshare/nfs2
exporting *:/nfsshare/nfs1
[root@localhost ~]# systemctl start nfs-server
[root@localhost ~]# systemctl enable nfs-server
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
####################

1.安装访问共享软件
yum install nfs-utils -y

2.识别共享
showmount -e 172.25.254.250

####################
[root@localhost ~]# showmount -e 172.25.50.100
Export list for 172.25.50.100:
/nfsshare/nfs5 *
/nfsshare/nfs4 *
/nfsshare/nfs3 *
/nfsshare/nfs2 *
/nfsshare/nfs1 *
####################

3.使用共享
mount 172.25.254.250:/nfsshare/nfs1 /mnt

####################
[root@localhost ~]# mount 172.25.50.100:/nfsshare/nfs1 /mnt
[root@localhost ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3159128   7314772  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      80    508916   1% /dev/shm
tmpfs                           508996   13348    495648   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3159168   7314816  31% /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# touch 123
[root@localhost mnt]# ls
123
[root@localhost mnt]# ls /nfsshare/nfs1/
123
####################

4.自动挂载
方法1)
vim /etc/fstab
172.25.254.250:/nfsshare/nfs1    /mnt    nfs    defaults 0 0

方法2)
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

####################
[root@localhost ~]# ll /net
ls: cannot access /net: No such file or directory
[root@localhost ~]# systemctl start autofs
[root@localhost ~]# ll /net
total 0
[root@localhost ~]# ll -d /net
drwxr-xr-x. 2 root root 0 Nov 15 20:36 /net
####################

3.访问
cd /net/172.25.254.250/nfsshare/nfs1

####################
[root@localhost ~]# cd /net/172.25.50.100/nfsshare/nfs1
[root@localhost nfs1]# ls
123
[root@localhost nfs1]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3174544   7299356  31% /
devtmpfs          493408       0    493408   0% /dev
tmpfs             508996      84    508912   1% /dev/shm
tmpfs             508996   13368    495628   3% /run
tmpfs             508996       0    508996   0% /sys/fs/cgroup
/dev/vda1       10473900 3174544   7299356  31% /net/172.25.50.100/nfsshare/nfs1
>发现挂载设备是/dev/vda1。由于服务端和客户端都是desktop,效果不太好,打开虚拟机server进行测试。
server:
[root@localhost ~]# showmount -e 172.25.50.100            ##输出省略
[root@localhost ~]# vim /etc/yum.repos.d/rhel_dvd.repo        ##输出省略
[root@localhost ~]# yum install autofs -y            ##输出省略
[root@localhost ~]# systemctl start autofs
[root@localhost ~]# cd /net/172.25.50.100/nfsshare/nfs1
[root@localhost nfs1]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149760   7324140  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13368    495628   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174656   7299328  31% /net/172.25.50.100/nfsshare/nfs1
[root@localhost nfs1]# cd
[root@localhost ~]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149760   7324140  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13368    495628   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174656   7299328  31% /net/172.25.50.100/nfsshare/nfs1
####################

4.设定空闲卸载时间
vim /etc/autofs.conf
15 timeout = 3        ##闲置3秒后系统自动卸载网络设备

systemctl restart autofs

autofs默认退出等待时间是300秒,只针对nfs

####################
server:
[root@localhost ~]# vim /etc/sysconfig/autofs
--------------------------------------------------
将第13行
 13 TIMEOUT=300
修改为
 13 TIMEOUT=3
:wq
--------------------------------------------------
[root@localhost ~]# systemctl restart autofs.service
[root@localhost ~]# cd /net/172.25.50.100/nfsshare/nfs1
[root@localhost nfs1]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149764   7324136  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13368    495628   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174656   7299328  31% /net/172.25.50.100/nfsshare/nfs1
[root@localhost nfs1]# cd
[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3149764   7324136  31% /
devtmpfs          493408       0    493408   0% /dev
tmpfs             508996      84    508912   1% /dev/shm
tmpfs             508996   13368    495628   3% /run
tmpfs             508996       0    508996   0% /sys/fs/cgroup
####################

5.实现自定义共享挂载点
vim /etc/auto.master
最终自定义挂载点的上层目录        子配置文件
/mnt                /etc/auto.nfs

vim子配置文件
最终挂载点        网络共享目录
vim /etc/auto.nfs
pub1        172.25.254.250:/nfsshare/nfs1
*        172.25.254.250:/nfsshare&        ##指定任意共享挂载

systemctl restart autofs

####################
server:
[root@localhost ~]# vim /etc/auto.master
--------------------------------------------------
 13 /net    -hosts
在13行下面插入一行
 14 /mnt    /etc/auto.nfs
:wq
--------------------------------------------------
[root@localhost ~]# ll /etc/auot.nfs
ls: cannot access /etc/auot.nfs: No such file or directory
[root@localhost ~]# vim /etc/auto.nfs
--------------------------------------------------
pub1    172.25.50.100:/nfsshare/nfs1
:wq
--------------------------------------------------
[root@localhost ~]# systemctl restart autofs.service
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
[root@localhost mnt]# cd pub1
[root@localhost pub1]# ls
123
[root@localhost pub1]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149840   7324060  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13368    495628   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174656   7299328  31% /mnt/pub1
[root@localhost pub1]# cd
[root@localhost ~]# vim /etc/auto.nfs
--------------------------------------------------
*       172.25.50.100:/nfsshare/&
:wq
--------------------------------------------------
[root@localhost ~]# systemctl restart autofs.service
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
[root@localhost mnt]# cd nfs1
[root@localhost nfs1]# ls
123
[root@localhost nfs1]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149848   7324052  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13396    495600   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174784   7299200  31% /mnt/nfs1
[root@localhost nfs3]# cd /mnt/nfs2
[root@localhost nfs2]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149848   7324052  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13396    495600   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs1  10473984 3174656   7299328  31% /mnt/nfs1
[root@localhost nfs2]# ls
[root@localhost nfs2]# df
Filesystem                   1K-blocks    Used Available Use% Mounted on
/dev/vda1                     10473900 3149848   7324052  31% /
devtmpfs                        493408       0    493408   0% /dev
tmpfs                           508996      84    508912   1% /dev/shm
tmpfs                           508996   13396    495600   3% /run
tmpfs                           508996       0    508996   0% /sys/fs/cgroup
172.25.50.100:/nfsshare/nfs2  10473984 3174656   7299328  31% /mnt/nfs2
####################


####################
#### vsftpd服务    ####
####################

1.什么是ftp

2.安装ftp
yum install vsftpd  -y
systemctl start vsftpd
systemctl stop firewalld
systemctl enable vsftpd
setenforce 0
lftp ip                    ##能登陆并且显示,表示安装成功

3.vsftpd文件信息
/var/ftp        ##默认发布目录
/etc/vsftpd        ##配置目录

4.vsftpd服务的配置参数
1)匿名用户设定
anonymous_enable=YES|NO            ##匿名用户登陆限制

#<匿名用户上传>
vim /etc/vsftpd/vsftpd.conf
write_enable=YES
anon_upload_enable=YES
chgrp ftp /var/ftp/pub
chmod 775 /var/ftp/pub

#<匿名用户家目录修改>
anon_root=/direcotry

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

#<匿名用户建立目录>
anon_mkdir_write_enable=YES|NO

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

#<匿名用户删除>
anon_other_write_enable=YES|NO

####################
服务端:
[root@server ~]# yum install vsftpd -y
......
[root@server ~]# systemctl start vsftpd
[root@server ~]# systemctl enable vsftpd
[root@server ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
    
[root@server ~]# firewall-cmd --permanent --add-service=ftp
success
[root@server ~]# firewall-cmd --reload
success
[root@server ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client ftp ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
    
客户端:
[root@desktop ~]# yum install lftp -y
......
[root@desktop ~]# lftp 172.25.50.200
lftp 172.25.50.200:~> ls              
drwxr-xr-x    2 0        0               6 Mar 07  2014 pub
lftp 172.25.50.200:~> cd pub/
cd ok, cwd=/pub
lftp 172.25.50.200:/pub> ls
服务端:
[root@server ~]# cd /var/ftp/pub
[root@server pub]# ls
[root@server pub]# touch file{1..3}
客户端:
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
lftp 172.25.50.200:~> exit
服务端:
[root@server pub]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 12 anonymous_enable=NO
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
[root@desktop ~]# lftp 172.25.50.200
lftp 172.25.50.200:~> ls
Interrupt                          
lftp 172.25.50.200:~> exit
[root@desktop ~]#
服务端:
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 12 anonymous_enable=YES

 29 anon_upload_enable=YES
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
[root@desktop ~]# lftp 172.25.50.200
lftp 172.25.50.200:~> ls
drwxr-xr-x    2 0        0              42 Nov 16 09:24 pub
lftp 172.25.50.200:/> cd pub/
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
lftp 172.25.50.200:/pub> put /etc/passwd
put: Access failed: 553 Could not create file. (passwd)
服务端:
[root@server pub]# ll /var/ftp
total 0
drwxr-xr-x. 2 root root 42 Nov 16 04:24 pub
[root@server pub]# chmod 777 /var/ftp/pub
[root@server pub]# ll /var/ftp
total 0
drwxrwxrwx. 2 root root 42 Nov 16 04:24 pub
客户端:
lftp 172.25.50.200:/pub> put /etc/passwd
put: Access failed: 553 Could not create file. (passwd)
服务端:
[root@server pub]# setenforce 0        ##selinux警告模式;"setenforce 1"selinux禁止模式
[root@server pub]# getenforce
Permissive
客户端:
lftp 172.25.50.200:/pub> put /etc/passwd
2005 bytes transferred
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
-rw-------    1 14       50           2005 Nov 16 09:57 passwd
服务端:
[root@server pub]# chgrp ftp /var/ftp/pub/
[root@server pub]# chmod 775 /var/ftp/pub/
[root@server pub]# ll /var/ftp/
total 0
drwxrwxr-x. 2 root ftp 55 Nov 16 04:57 pub
客户端:
lftp 172.25.50.200:/pub> get passwd
get: Access failed: 550 Failed to open file. (passwd)
服务端:
[root@server pub]# man 5 vsftpd.conf
--------------------------------------------------
       anon_world_readable_only
              When enabled, anonymous users will only be allowed  to  download
              files which are world readable. This is recognising that the ftp
              user may own files, especially in the presence of uploads.

              Default: YES
--------------------------------------------------
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 30 anon_world_readable_only=NO
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
lftp 172.25.50.200:/pub> get passwd
2005 bytes transferred
lftp 172.25.50.200:/pub> !ls
anaconda-ks.cfg  Documents  Music   Pictures  Templates
Desktop         Downloads  passwd  Public    Videos
lftp 172.25.50.200:/pub> mkdir westos
mkdir: Access failed: 550 Permission denied. (westos)
服务端:
[root@server pub]# man 5 vsftpd.conf
--------------------------------------------------
       anon_mkdir_write_enable
              If set to YES, anonymous users will be permitted to  create  new
              directories  under  certain  conditions.  For  this to work, the
              option write_enable must be activated,  and  the  anonymous  ftp
              user must have write permission on the parent directory.

              Default: NO
--------------------------------------------------
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 34 anon_mkdir_write_enable=YES
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
lftp 172.25.50.200:/pub> mkdir westos
mkdir ok, `westos‘ created
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
-rw-------    1 14       50           2005 Nov 17 01:08 passwd
drwx------    2 14       50              6 Nov 17 01:29 westos
lftp 172.25.50.200:/pub> rm passwd
rm: Access failed: 550 Permission denied. (passwd)
服务端:
[root@server pub]# man 5 vsftpd.conf
--------------------------------------------------
       anon_other_write_enable
              If  set  to  YES,  anonymous  users will be permitted to perform
              write operations other than upload and create directory, such as
              deletion  and  renaming.  This  is generally not recommended but
              included for completeness.

              Default: NO
--------------------------------------------------
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 35 anon_other_write_enable=YES
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
lftp 172.25.50.200:/pub> rm passwd
rm ok, `passwd‘ removed
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
drwx------    2 14       50              6 Nov 17 01:29 westos
lftp 172.25.50.200:/pub> rm westos
rm: Access failed: 550 Delete operation failed. (westos)
lftp 172.25.50.200:/pub> rm -r westos
rm ok, `westos‘ removed                
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
服务端:
[root@server pub]# man 5 vsftpd.conf
--------------------------------------------------
       anon_root
              This option represents a directory  which  vsftpd  will  try  to
              change  into  after  an  anonymous  login.  Failure  is silently
              ignored.

              Default: (none)
--------------------------------------------------
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 36 anon_root=/home
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
[root@server pub]# ls /home
student
客户端:
lftp 172.25.50.200:/pub> exit
[root@desktop ~]# lftp 172.25.50.200
lftp 172.25.50.200:~> ls
drwx------    4 1000     1000           84 Jul 10  2014 student
lftp 172.25.50.200:/> mkdir westos
mkdir: Access failed: 550 Create directory operation failed. (westos)
服务端:
[root@server pub]# man 5 vsftpd.conf
--------------------------------------------------
       anon_umask
              The  value that the umask for file creation is set to for anony‐
              mous users. NOTE! If you want to specify octal values,  remember
              the  "0" prefix otherwise the value will be treated as a base 10
              integer!

              Default: 077
--------------------------------------------------
[root@server pub]# vim /etc/vsftpd/vsftpd.conf
--------------------------------------------------
 36 anon_umask=022
 37 #anon_root=/home
:wq
--------------------------------------------------
[root@server pub]# systemctl restart vsftpd
客户端:
lftp 172.25.50.200:/> exit
[root@desktop ~]# lftp 172.25.50.200
lftp 172.25.50.200:~> cd pub/
cd ok, cwd=/pub
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
lftp 172.25.50.200:/pub> put /etc/passwd
2005 bytes transferred      
lftp 172.25.50.200:/pub> ls
-rw-r--r--    1 0        0               0 Nov 16 09:24 file1
-rw-r--r--    1 0        0               0 Nov 16 09:24 file2
-rw-r--r--    1 0        0               0 Nov 16 09:24 file3
-rw-r--r--    1 14       50           2005 Nov 17 01:48 passwd
####################

本文出自 “施超Linux学习笔记” 博客,谢绝转载!

Linux课程第十五天学习笔记