smb

关闭防火墙并且重启网络
yum install samba  samba-client samba-commmon -y

smb
systemctl start smb

smb

smbclient -L //172.25.254.104 匿名用户登陆(vim /etc/hosts)

smb
pdbedit -L 显示smb用户
smbpasswd -a kiosk添加smb用户 只能添加系统上已经存在的

[[email protected] ~]# smbpasswd -a kiosk
New SMB password:
Retype new SMB password:
Failed to add entry for user kiosk.    //用系统没有的用户登陆就是失败

smb
[[email protected] ~]# smbpasswd -a student
New SMB password:
Retype new SMB password:
Added user student.                     //成功

smb
[[email protected] ~]# useradd mos            //添加cq用户               
[[email protected] ~]# smbpasswd -a mos        ///添加amb用户
New SMB password:
Retype new SMB password:
Added user mos.

smb
[[email protected] ~]# pdbedit -L           // 列出smb用户
student:1000:Student User
cq:1001:

smb
[[email protected] ~]# pdbedit -x        //删除 smb用户
[[email protected] ~]# pdbedit -L
student:1000:Student User
smbclient -L //172.25.254.205 -U student       // 以某一个用户登陆

smb

smb

ls 与 !ls                             ls为列出共享目录的文件,!ls为列出,所在所在目录里的文件
 mount //172.25.254.205/student /mnt/ -o username=student,password=123    挂载共享文件目录到mnt
[[email protected] ~]# mount -a
[[email protected] ~]# df

smb
vim /etc/fstab  //设置开机挂载
//172.25.254.205/student /mnt cifs  username=student,password=mos 0 0
此时把文件系统挂载在mnt目录下.这样就可以向共享文件系统里写文件了。

smb

smb

vim /etc/sysconfig/selinux
改成enforcing
重新启动系统
此时访问不了共享目录关闭火墙 打开smb
smbclient //172.25.254.205/student -U student
 //当selinux开启时,不能和查看共享文件系统

smb
[[email protected] ~]# getsebool -a | grep samb              查看共享文件系统的开关
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off

smb
[[email protected] ~]# setsebool -P samba_create_home_dirs on
[[email protected] ~]# setsebool -P samba_enable_home_dirs on  //打开创建目录查看目录的权限
 
[[email protected] ~]# vim /etc/samba/smb.conf          创建共享目录,并指定路径
         [linux]
         comment = dir from westos
         path = /westos

smb
[[email protected] ~]# mkdir /westos/file{1..4}
[[email protected] ~]# systemctl start samb             重新启动
[[email protected] ~]# smbclient //172.25.254.205/student -U student  发现查看不了文件

smb
setenforce 0       把selinux变为警告模式
[[email protected] ~]# smbclient //172.25.254.104/student -U student 可以查看

smb

[[email protected] ~]# restorecon -RvvF /westos/
[[email protected] ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?' //  查看配置文件后发现安全上下文不一致,生成安全上下文

smb
[[email protected] ~]#  serenforce 1  //此时开启selinux
[[email protected] ~]# smbclient //172.25.254.205/student -U student //可以查看

smb
[[email protected] /]# vim /etc/samba/smb.conf
         [linux]
         comment = dir from westos
         path = /westos
         [mnt]
         comment = dir from westos
         path = /mnt                 //设置系统共享目录

smb

[[email protected] /]# systemctl restart smb

[[email protected] ~]# setsebool -P samba_export_all_ro on  //开启一个大的权限不需要修改安全上下文就可以查看所有。

[[email protected] /]# smbclient -L //172.25.254.205 -U student //查看可以共享的目录
rm -rf /westos
mkdir /westos
touch /westos/file{1..4}
此时查看就不需要改安全上下文

smb

 

[[email protected] /]# showmount -e 172.25.254.105
clnt_create: RPC: Program not registered /客户端nfs没有

[[email protected] ~]# systemctl start nfs /服务器上安装开启nfs
[[email protected] ~]# yum install nfs-utils
[[email protected] ~]# vim /etc/exports   编辑文件
/westos               *(sync)  /以sync的方式共享/westos上的文件

[[email protected] ~]# exportfs -rv 重载,这个文件不能通过重其来生效
 exporting *:/westos
 

自动化挂载:

在客户端安装 yum install autofs.x86_64 -y
systemctl start autofs
vim /etc/sysconfig/autofs 配置文件可以更改停止时间
systemctl restart autofs.service
cd /net/172.25.254.105/westos/ 共享文件目录


实际挂载目录为  /net/172.25.254.105/westos/
vim /etc/auto.master 修改挂载目录
/opt/nfs     /etc/auto.nfs
vim /etc/auto.nfs
westos  -ro   172.25.254.100:/westos

systemctl restart autofs.service


vim /etc/auto.nfs
/westos    *(rw,sync) 使文件具有可写的权限
/westos    *(rw,sync,anonuid=1001)指定文件产生的所有人
/westos    *(ew,sync,anonuid=1001,anongid=1000)指定文件所有组所有人
/westos    *(rw,sync,no_root_squash)    默认所有组所有人为root
/westos    *(ro) 172.25.254(rw,sync,no_rooot_squash)除了这个ip外的所有主机都仅仅有只读权限
exportfs -rv刷新