smaba

简介:

samba

1samba作用

提供cifs协议实现共享文件

2安装

yum install samba samba-common samba-client -y

systemctl start smb nmb

systemctl enable smb nmb

3添加smb用户

首先系统中要有用户

[root@westos ~]# id student

uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)

[root@westos ~]# smbpasswd -a student  创建smb用户

New SMB password:

Retype new SMB password:

Added user student.

[root@westos ~]# pdbedit -L  查看smb用户信息

student:1000:Student User

[root@westos ~]# pdbedit -x student  删除smb用户

[root@westos ~]# pdbedit -L

[root@westos ~]# setsebool -P samba_enable_home_dirs on  在selinux中可以访问自己的家目录

测试

[root@westos ~]# smbclient //172.25.254.114/student -U student

Enter student's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Thu Jul 10 19:06:52 2014

  ..                                  D        0  Thu Jul 10 18:19:09 2014

  .bash_logout                        H       18  Wed Jan 29 07:45:18 2014

  .bash_profile                       H      193  Wed Jan 29 07:45:18 2014

  .bashrc                             H      231  Wed Jan 29 07:45:18 2014

  .ssh                               DH        0  Thu Jul 10 18:19:10 2014

  .config                            DH        0  Thu Jul 10 19:06:53 2014


40913 blocks of size 262144. 28544 blocks available

4共享目录

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

        [jj]                     共享名称

        comment = local.public   对共享目录的描述

        path = /mnt        共享目录的绝对路径

        workgroup = WESTOS  共享目录的组

当共享目录为用户自建目录时

[root@westos mnt]# mkdir /smbshare

[root@westos mnt]# touch /smbshare/westosxxx

[root@westos mnt]# vim /etc/samba/smb.conf 

        [jj]

        comment = local.public

        path = /smbshare

[root@westos mnt]# setsebool -P samba_enable_home_dirs 0

[root@westos mnt]# semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'

/etc/selinux/targeted/contexts/files/file_contexts.local:  line 4 has invalid regex /smbshare(/.*)?:  missing )

PCRE compilation failed for ^/smbshare(/.*)?$ at offset 21: missing )

libsemanage.sefcontext_compile: sefcontext_compile returned error code 255. Compiling /etc/selinux/targeted/contexts/files/file_contexts.local

/etc/selinux/targeted/contexts/files/file_contexts.local:  line 4 has invalid regex /smbshare(/.*)?:  missing )

PCRE compilation failed for ^/smbshare(/.*)?$ at offset 21: missing )

libsemanage.sefcontext_compile: sefcontext_compile returned error code 255. Compiling /etc/selinux/targeted/contexts/files/file_contexts.local

ValueError: Could not commit semanage transaction

[root@westos mnt]# restorecon -RvvF /smbshare

[root@westos mnt]# smbclient //172.25.254.114/jj -U student

Enter student's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 02:36:48 2017

  ..                                  D        0  Sat Jun  3 02:36:38 2017

  westosxxx                           N        0  Sat Jun  3 02:36:48 2017


40913 blocks of size 262144. 28544 blocks available

smb: \> 

semanage fcontext -a -t samba_share_t '目录名称(/.*)?‘  配置安全上下文

restorecon -RvvF 目录名称 



当共享目录为系统目录时

[root@westos ~]# touch /mnt/file{1..10}

[root@westos ~]# cd /mnt

[root@westos mnt]# ls

file1  file10  file2  file3  file4  file5  file6  file7  file8  file9

[root@westos mnt]# smbclient //172.25.254.114/jj -U student

Enter student's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Thu Jul 10 19:06:52 2014

  ..                                  D        0  Thu Jul 10 18:19:09 2014

  .bash_logout                        H       18  Wed Jan 29 07:45:18 2014

  .bash_profile                       H      193  Wed Jan 29 07:45:18 2014

  .bashrc                             H      231  Wed Jan 29 07:45:18 2014

  .ssh                               DH        0  Thu Jul 10 18:19:10 2014

  .config                            DH        0  Thu Jul 10 19:06:53 2014


40913 blocks of size 262144. 28545 blocks available

smb: \> 

[root@westos mnt]# setsebool -P samba_export_all_ro on  只读共享

[root@westos mnt]# setsebool -P samba_export_all_rw on  读写共享

[root@westos ~]# setsebool -P samba_enable_home_dirs on

[root@westos mnt]# smbclient //172.25.254.114/jj -U student

Enter student's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 02:28:28 2017

  ..                                  D        0  Sat Jun  3 01:30:28 2017

  file1                               N        0  Sat Jun  3 02:28:28 2017

  file2                               N        0  Sat Jun  3 02:28:28 2017

  file3                               N        0  Sat Jun  3 02:28:28 2017

  file4                               N        0  Sat Jun  3 02:28:28 2017

  file5                               N        0  Sat Jun  3 02:28:28 2017

  file6                               N        0  Sat Jun  3 02:28:28 2017

  file7                               N        0  Sat Jun  3 02:28:28 2017

  file8                               N        0  Sat Jun  3 02:28:28 2017

  file9                               N        0  Sat Jun  3 02:28:28 2017

  file10                              N        0  Sat Jun  3 02:28:28 2017


40913 blocks of size 262144. 28545 blocks available

smb: \> 



匿名用户登陆

[root@westos mnt]# smbclient //172.25.254.114/jj 

Enter root's password: 

Anonymous login successful

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

tree connect failed: NT_STATUS_ACCESS_DENIED

[root@westos mnt]# vim /etc/samba/smb.conf 

123         security = user

124         passdb backend = tdbsam

125         map to guest = bad user

321         [jj]

322         comment = local.public

323         path = /smbshare

324         guest ok = yes

[root@westos mnt]# systemctl  restart smb.service 

[root@westos mnt]# smbclient //172.25.254.114/jj 

Enter root's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 02:36:48 2017

  ..                                  D        0  Sat Jun  3 02:36:38 2017

  westosxxx                           N        0  Sat Jun  3 02:36:48 2017


40913 blocks of size 262144. 28545 blocks available

smb: \> 

访问控制

hosts allow = 域名  仅允许

host deny = 域名  仅拒绝

        [jj]

        comment = local.public

        path = /smbshare

        valid users = westos    当前共享有效用户

        valid users = +westos   当前共享有效用户组

        valid users = @westos   当前共享有效用户组

[root@westos mnt]# smbclient //172.25.254.114/jj -U student

Enter student's password: 

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

tree connect failed: NT_STATUS_ACCESS_DENIED

所有用户均可写

服务器

[root@westos mnt]# vim /etc/samba/smb.conf 

       [jj]

        comment = local.public

        path = /mnt

        writable = yes                是否可写

[root@westos mnt]# setsebool -P samba_export_all_rw on  

[root@westos mnt]# chmod o+w /mnt

客机

[root@foundation14 ~]# mount -o username=student,password=westos //172.25.254.114/jj /mnt/  【smb共享目录】                   【smb用户名以及密码】

[root@foundation14 ~]# cd /mnt

[root@foundation14 mnt]# ls

file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  jj

[root@foundation14 mnt]# touch kill

[root@foundation14 mnt]# ls

file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  jj  kill

[root@foundation14 mnt]# 

指定用户可写

write list = student        可写用户

write list = +student       可写用户组

write list = @student       

admin users = westos      共享超级用户指定

smb多用户挂载

在客机上【不在服务器】

[root@foundation14 ~]# vim /root/westos

username=student

password=westos

[root@foundation14 ~]# chmod 600 /root/westos

[root@foundation14 ~]# yum install cifs-utils -y

[root@foundation14 ~]# mount -o credentials=/root/westos,multiuser,sec=ntlmssp //172.25.254.114/jj /mnt/

credentials=/root/westos 指定挂载时的认证文件

sec=ntlmssp  smb认证方式

multiuser  支持多用户认证



测试

su - kiosk

ls /mnt

[kiosk@foundation14 ~]$ ls /mnt

ls: cannot access /mnt: Permission denied    没有认证无法访问

[kiosk@foundation14 ~]$ cifscreds add -u student 172.25.254.114  认证

Password: 

[kiosk@foundation14 ~]$ ls /mnt

file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  jj  kill


                  













本文转自铁骑传说51CTO博客,原文链接:http://blog.51cto.com/ybzbfs/1933551 ,如需转载请自行联系原作者




相关文章
|
2月前
|
监控 安全 Linux
深入探讨Samba服务器的配置与使用
深入探讨Samba服务器的配置与使用
168 0
|
存储 网络协议 安全
Linux 在线/离线安装 NFS 服务及使用
-m 表示指定文件所在的文件系统或者块设备(处于 mount 状态)。所有访问该文件系统的进程都被列出。如上所示,有两个进程占用了,将其kill掉,再重新取消挂载。
2207 0
Linux 在线/离线安装 NFS 服务及使用
|
5月前
|
Ubuntu Linux 网络安全
1. Linux环境搭建及创建共享文件的方法
1. Linux环境搭建及创建共享文件的方法
158 1
|
11月前
|
网络协议 Unix Linux
Samba服务的安装与配置
Samba服务的安装与配置
2422 0
|
3月前
|
Linux Windows
Linux系统安装Samba服务器
在实际开发中,我们经常会有跨系统之间文件传递的需求,Samba便是能够在Windows和Linux之间传递文件的服务,功能也是非常强大和好用,本篇文章将介绍如何在Linux系统上安装Samba服务,以CentOS7系统为例。
65 0
|
3月前
|
Ubuntu Linux Windows
window10 虚拟机 linux ubuntu 环境下samba服务器配置
本文的目的是在windows 10 系统,使用samba服务实现 windows 10共享虚拟机ubuntu系统的文件。
44 0
|
3月前
|
算法 Ubuntu Unix
【Linux】文件服务Samba
【Linux】文件服务Samba
37 0
|
4月前
|
存储 缓存 Apache
小白带你学习linuxAPACHE安装和管理 (二十)
小白带你学习linuxAPACHE安装和管理 (二十)
38 0
|
9月前
|
安全 关系型数据库 MySQL
阿里云服务器安装MySQL及配置
阿里云服务器安装MySQL及配置
1132 0
|
10月前
|
存储 应用服务中间件 Apache
linux-NFS存储服务搭建
linux-NFS存储服务搭建
143 0