nfs 和samba

  • NFS,是Network File System的简写,即网络文件系统。网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS. NFS允许一个系统在网络上与他人共享目录和文件。通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件。
  • • 模式: C/S 模式
    • 端口:
    • RHEL6是以NFSv4作为默认版本,NFSv4使用TCP协议(端口号是2049)和NFS服务器建立连接

nfs安装

[root@ygy130 ~]# yum -y install nfs*

查看服务端口号

[root@ygy130 ~]# cat /etc/services | grep nfs 

[root@ygy130 ~]# netstat -antpu | grep 2049

直接启动会报错,要先启动rpcbind 

[root@ygy130 ~]# /etc/init.d/rpcbind start

[root@ygy130 ~]# service nfs start

写配置文件,共享目录为/media  *表示给所有用户rw权限

 [root@ygy130 ~]# vim /etc/exports

[root@ygy130 ~]# chmod 777 /media/ -R    其他用户有操作这个文件夹的权限

130做服务端,131做客户端

[root@yu131 ~]# yum install showmount

[yy@yu131 ~]$ showmount -e 192.168.1.130
Export list for 192.168.1.130:
/media *

 [root@yu131 ~]# mount -t nfs 192.168.1.130:/media /opt

-t 指定文件系统。

开机自动挂载

[root@yu131 ~]# vim /etc/fstab 

配置文件:

共享目录, ip,共享方式

samba: 跨平台Linux和windows之间共享文件。

端口号: 139 和 445 

安装

[root@ygy130 ~]# yum install samba samba-client

开机自启动

[root@ygy130 ~]# chkconfig smb on

 启动:

service smb start  /etc/init.d/smb restart

创建一个共享目录

 [root@ygy130 ~]# mkdir /share

[root@ygy130 ~]# chmod 777 /share

修改配置文件

[root@ygy130 ~]# vim /etc/samba/smb.conf 

security = share     匿名共享不需要账号名和密码

#security = user     需要用户名和密码登陆

[smbshare]
comment = share Directories
path = /share
public = yes
#readonly = yes
writable = yes

保存,重启服务,使用win+r下面就可以访问linux的共享目录了。

使用密码登陆samba服务器

[root@ygy130 ~]# smbpasswd -a yy

[root@ygy130 ~]# smbpasswd -a ygy

[root@ygy130 ~]# vim /etc/samba/smb.conf 

 security = user  

[smbshare]
comment = share Directories
path = /share
public = yes
#readonly = yes
writable = yes
valid user = @ygy yy  #指定用户组或者单个用户

双网卡都登陆成功!

 

[smbshare]
comment = share Directories
path = /share
public = yes
#readonly = yes
#writable = yes
valid user = @ygy yy
write list = yy

设置权限,ygy组有登陆的权限,但是没有写的权限

browseable = no

直接访问是访问不了的,可以通过绝对路径来查看文件

指定某个用户可以看见隐藏的目录

修改配置文件

browseable = no

[root@ygy130 ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.ygy

 [root@ygy130 ~]# vim /etc/samba/smb.conf.ygy 

扩展参数:
客户端访问控制
hosts allow 和 hosts deny 的使用方法
1)hosts allow 和 hosts deny 字段的使用
hosts allow 字段定义允许访问的客户端
hosts deny 字段定义禁止访问的客户端

这里我们添加hosts deny 和hosts allow 字段
hosts deny = 192.168.0. 表示禁止所有来自192.168.0.0/24 网段的IP 地址访问
hosts allow = 192.168.0.24 表示允许192.168.0.24 这个IP 地址访问
hosts allow = 192.168.1. EXCEPT 192.169.1.102
表示允许1网段的用户访问,除了102这个地址
当host deny 和hosts allow 字段同时出现并定义滴内容相互冲突时,hosts allow 优先。

linux共享windows文件夹:待研究

原文地址:https://www.cnblogs.com/yuguangyuan/p/5914701.html