linu samba服务
关闭防火墙并且重启网络
yum install samba samba-client samba-commmon -y
systemctl start smb
yum install samba samba-client samba-commmon -y
systemctl start smb
smbclient -L //172.25.254.104 匿名用户登陆(vim /etc/hosts)
pdbedit -L 显示smb用户
smbpasswd -a student 添加smb用户 只能添加系统上已经存在的
pdbedit -L 显示smb用户
smbpasswd -a student 添加smb用户 只能添加系统上已经存在的
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214138388-1237772380.png)
[root@localhost ~]# pdbedit -x cq 删除 smb用户
[root@localhost ~]# pdbedit -L
[root@localhost ~]# pdbedit -L
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214313263-318549371.png)
smbclient -L //172.25.254.103 -U student 以某一个用户登陆
ls 与 !ls ls为列出共享目录的文件,!ls为列出,所在所在目录里的文件
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214441043-1110264355.png)
mount //172.25.254.103/student /mnt/ -o username=student,password=111 挂载共享文件目录到mnt
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214546319-128543658.png)
cd /mnt
touch westos{1..9}
smbclient //172.25.254.103/student -U student
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214641163-533118796.png)
vim /etc/fstab 设置开机挂载
此时把文件系统挂载在mnt目录下.这样就可以向共享文件系统里写文件了。
vim /etc/sysconfig/selinux
改成enforcing
重新启动系统
此时访问不了共享目录关闭火墙 打开smb
smbclient //172.25.254.104/student -U student
Enter student's password:
Connection to 172.25.254.104 failed (Error NT_STATUS_CONNECTION_REFUSED) //当selinux开启时,不能和查看共享文 件系统
getsebool -a | grep samb 查看共享文件系统的开关
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215023697-936679317.png)
[root@localhost ~]# setsebool -P samba_create_home_dirs on
[root@localhost ~]# setsebool -P samba_enable_home_dirs on //打开创建目录查看目录的权限
[root@localhost ~]# vim /etc/samba/smb.conf 创建共享目录,并指定路径
[linux]
comment = dir from westos
path = /westos
[root@localhost ~]# mkdir /westos/file{1..3}
[root@localhost ~]# systemctl start samb 重新启动
[root@localhost ~]# smbclient //172.25.254.104/student -U student 发现查看不了文件
setenforce 0 把selinux变为警告模式
[root@localhost ~]# smbclient //172.25.254.104/student -U student 可以查看
[root@localhost ~]# restorecon -RvvF /westos/
[root@localhost ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?' // 查看配置文件后发现安全上下文不一致,生成安全上下文
[root@localhost ~]# serenforce 1 //此时开启selinux
[root@localhost ~]# smbclient //172.25.254.104/student -U student //可以查看
[root@localhost ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?' // 查看配置文件后发现安全上下文不一致,生成安全上下文
[root@localhost ~]# serenforce 1 //此时开启selinux
[root@localhost ~]# smbclient //172.25.254.104/student -U student //可以查看
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815214939668-1646934229.png)
vim /etc/samba/smb.conf
[linux]
comment = dir from westos
path = /westos
[mnt]
comment = dir from westos
path = /mnt //设置系统共享目录
systemctl restart smb
setsebool -P samba_export_all_ro on //开启一个大的权限不需要修改安全上下文就可以查看所有。
smbclient -L //172.25.254.104 -U student //查看可以共享的目录
rm -rf /westos
mkdir /westos
touch /westos/file1
rm -rf /westos
mkdir /westos
touch /westos/file1
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215133840-606257018.png)
此时查看就不需要改安全上下文
yum install nfs-utils
systemctl start nfs 服务器上安装开启nfs
showmount -e 172.25.254.103
showmount -e 172.25.254.103
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215251674-1427230697.png)
vim /etc/exports 编辑文件
/westos *(sync) /以sync的方式共享/westos上的文件
/westos *(sync) /以sync的方式共享/westos上的文件
exportfs -rv 重载,这个文件不能通过重启来生效
exporting *:/westos
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215433835-1489156903.png)
自动化挂载:
在客户端安装 yum install autofs.x86_64 -y
systemctl start autofs
vim /etc/sysconfig/autofs 配置文件可以更改停止时间
systemctl restart autofs.service
systemctl start autofs
vim /etc/sysconfig/autofs 配置文件可以更改停止时间
systemctl restart autofs.service
cd /net/172.25.254.104/westos/ 共享文件目录
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215607128-1109764373.png)
实际挂载目录为 /net/172.25.254.103/westos/
vim /etc/auto.master 修改挂载目录
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215847003-1795282476.png)
vim /etc/auto.nfs
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215856385-1739376858.png)
systemctl restart autofs.service
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215930404-1846843004.png)
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215936055-548931273.png)
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815215945848-1092626669.png)
vim /etc/auto.nfs
/westos *(rw,sync) 使文件具有可写的权限
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815220003901-131937938.png)
/westos *(rw,sync,anonuid=1001) 指定文件产生的所有人
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815220029128-270738545.png)
/westos *(ew,sync,anonuid=1001,anongid=1000)指定文件所有组所有人
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815220149109-356156653.png)
/westos *(rw,sync,no_root_squash) 默认所有组所有人为root
![](https://images2018.cnblogs.com/blog/1443263/201808/1443263-20180815220128220-1985520863.png)
/westos *(ro) 172.25.254(rw,sync,no_rooot_squash)除了这个ip外的所有主机都仅仅有只读权限