linu samba服务

关闭防火墙并且重启网络
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用户 只能添加系统上已经存在的
                 
[root@localhost ~]# pdbedit -x cq            删除 smb用户
[root@localhost ~]# pdbedit -L

smbclient -L //172.25.254.103 -U student                 以某一个用户登陆
ls 与 !ls                                                                    ls为列出共享目录的文件,!ls为列出,所在所在目录里的文件
 


 mount //172.25.254.103/student /mnt/ -o username=student,password=111     挂载共享文件目录到mnt

cd /mnt

touch westos{1..9}

smbclient  //172.25.254.103/student  -U student    


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              查看共享文件系统的开关

[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 //可以查看

 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

此时查看就不需要改安全上下文
 
yum install nfs-utils
systemctl start nfs                                          服务器上安装开启nfs
 showmount -e 172.25.254.103
vim /etc/exports   编辑文件
/westos               *(sync)  /以sync的方式共享/westos上的文件

 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.104/westos/  共享文件目录

实际挂载目录为  /net/172.25.254.103/westos/

vim /etc/auto.master 修改挂载目录

vim /etc/auto.nfs
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外的所有主机都仅仅有只读权限
 

猜你喜欢

转载自www.cnblogs.com/zhengyipengyou/p/9484320.html
今日推荐