设为首页 收藏本站
查看: 495|回复: 0

[经验分享] SMB文件共享——实验篇

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-9-23 08:56:49 | 显示全部楼层 |阅读模式
实验环境:RHEL7.0
             服务器    server1.example.com    172.25.254.1
             客户端    server2.example.com    172.25.254.2

1.安装配置SMB
    1.1安装
[iyunv@server1 ~]# yum install samba samba-client -y
[iyunv@server1 ~]# systemctl start smb
[iyunv@server1 ~]# systemctl enable smb
    1.2配置火墙策略

[iyunv@server1 ~]#  firewall-cmd --permanent --add-service=samba
[iyunv@server1 ~]# firewall-cmd --permanent --add-service=samba-client
[iyunv@server1 ~]# firewall-cmd --reload
   1.3添加smb用户

[iyunv@server1 ~]# useradd willis     ##创建用户
[iyunv@server1 ~]# useradd student
[iyunv@server1 ~]# smbpasswd -a willis    ##新建为smb用户并加密
New SMB password:
Retype new SMB password:
Added user willis.
[iyunv@server1 ~]# smbpasswd -a student
New SMB password:
Retype new SMB password:
Added user student.
[iyunv@server1 ~]# pdbedit -L
willis:1001:
student:1002:
[iyunv@server1 ~]# smbclient -L //172.25.254.1 -U student  
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Sharename       Type      Comment
---------       ----      -------
IPC$            IPC       IPC Service (Samba Server Version 4.1.1)
student         Disk      Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment
---------            -------

Workgroup            Master
---------            -------
[iyunv@server1 ~]# smbclient  //172.25.254.1/student -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
  .                                   D        0  Thu Sep 22 18:33:14 2016
  ..                                  D        0  Thu Sep 22 18:33:14 2016
  .mozilla                           DH        0  Thu Aug  4 23:45:35 2016
  .bash_logout                        H       18  Wed Jan 29 20:45:18 2014
  .bash_profile                       H      193  Wed Jan 29 20:45:18 2014
  .bashrc                             H      231  Wed Jan 29 20:45:18 2014

34808 blocks of size 262144. 22711 blocks available
smb: \> quit

2. 改共享目录
    2.1 自建目录
[iyunv@server1 ~]# mkdir /share
[iyunv@server1 ~]# vim /etc/samba/smb.conf
       [test]
       comment = test share
       path = /share
[iyunv@server1 ~]# touch /share/file
[iyunv@server1 ~]# smbclient //172.25.254.1/test -U willis
Enter willis's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
  .                                   D        0  Thu Sep 22 20:15:26 2016
  ..                                  D        0  Thu Sep 22 18:41:38 2016
  file                                N        0  Thu Sep 22 20:15:26 2016

34808 blocks of size 262144. 22696 blocks available
smb: \>
    2.2共享系统目录
[iyunv@server1 ~]# vim /etc/samba/smb.conf
       [test]
       comment = test share
       path = /mnt
[iyunv@server1 ~]# ls /mnt/
[iyunv@server1 ~]# touch /mnt/file1
[iyunv@server1 ~]# smbclient //172.25.254.1/test -U willis
Enter willis's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
  .                                   D        0  Thu Sep 22 20:18:31 2016
  ..                                  D        0  Thu Sep 22 18:41:38 2016
  file1                               N        0  Thu Sep 22 20:18:31 2016

34808 blocks of size 262144. 22696 blocks available
smb: \>

3. 改工作组
[iyunv@server1 ~]# smbclient -L //172.25.254.1 -U willis
Enter willis's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Sharename       Type      Comment
---------       ----      -------
test            Disk      test share
IPC$            IPC       IPC Service (Samba Server Version 4.1.1)
willis          Disk      Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment
---------            -------

Workgroup            Master
---------            -------
[iyunv@server1 ~]#
[iyunv@server1 ~]# vim /etc/samba/smb.conf
         workgroup = willis
[iyunv@server1 ~]# smbclient -L //172.25.254.1 -U willis
Enter willis's password:
Domain=[WILLIS] OS=[Unix] Server=[Samba 4.1.1]

Sharename       Type      Comment
---------       ----      -------
test            Disk      test share
IPC$            IPC       IPC Service (Samba Server Version 4.1.1)
willis          Disk      Home Directories
Domain=[WILLIS] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment
---------            -------

Workgroup            Master
---------            -------
[iyunv@server1 ~]#


4. 允许/拒绝访问服务的主机设置
[iyunv@server1 ~]# vim /etc/samba/smb.conf   (随改立即生效)
         hosts deny = 172.25.254.2
    测试:
[iyunv@server2 ~]# smbclient -L //172.25.254.1 -U willis
Enter willis's password:
protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE

5.客户端挂载使用
    RHEL6 可匿名登陆并挂载(share级别)
    RHEL 7 不能匿名挂载
服务器端:
[iyunv@server1 ~]# vim /etc/samba/smb.conf
        security = user
        passdb backend = tdbsam
        map to guest = bad user    #添加此句

      [test]
      comment = test share
      path = /share
      guest ok = yes   #添加此句
[iyunv@server1 ~]# systemctl restart smb.service
客户端:
[iyunv@server2 mnt]# mount //172.25.254.1/test /mnt -o username=willis,password=redhat
[iyunv@server2 mnt]# df -h
//172.25.254.1/test    8.5G  3.0G  5.6G  35% /mnt

常用参数
[test]
Guest ok  = yes    # 匿名用户可登陆
Browseable = no    #隐藏共享
Writable = yes     #允许所有用户写入
Weite list =  student   #只允许student写入
Write list = +student
Write list = @student    #允许student用户组写入  +和@功能一样
Valid users = +student    #test这个组只能student用户组使用
Admin users = student    # student是以root身份运行


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-276192-1-1.html 上篇帖子: 文件服务器迁移之三(Robocopy进行大量迁移) 下篇帖子: linux防暴力破解远程密码神器-fail2ban
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表