linux-SMB文件共享

简介:

################SMB文件共享###############


用internet文件系统(CIFS)也成为服务器是使用于MicrosftWindows服务器和客户端的标准文件和打印机共享系统信息块(SMB)
Samba服务可用于将Linux文件系统作为CIFS/SMB网络文件共享进行共享,并将Linux打印机作为CIFS/SMB打印机共享进行共享
软件包:
Samba-common  Samba的支持文件
Samba-client  客户端应用程序
Samba         服务器应用程序

服务器名称:smb  nmb
服务端口:通常使用TCP/445进行所有连接。还使用UDP137、UDP138和TCP/139进行向后兼容
主配置文件:/etc/samba/smb.conf


*)安装服务####################


[root@desktop ~]# yum search samba 

[root@desktop ~]# yum install samba-client.x86_64 samba-common.x86_64 samba.x86_64 -y 安装smb服务

[root@desktop ~]# systemctl start smb   开启服务

[root@desktop ~]# netstat -antlupe | grep smb查看服务端口(两个服务)

[root@desktop ~]# netstat -antlupe | grep nmb

Screenshot from 2017-12-04 10-44-15.png

[root@station ~]# smbclient -L //172.25.12.12   查看(匿名)

Enter root's password:  回车
Anonymous login successful  匿名



Screenshot from 2017-12-04 12-21-47.png


*)创建smb用户#######################


Screenshot from 2017-12-04 19-44-37.png


创建smb用户,用户必须是系统已有的用户

[root@station ~]# pdbedit -L     查看smb用户

[root@station ~]#

[root@station ~]# smbpasswd -a student   创建smb用户 Screenshot from 2017-12-04 12-26-48.png


系统没有的用户,不能加入,如下

[root@station ~]# smbpasswd -a westos

Screenshot from 2017-12-04 12-31-42.png

[root@station ~]# smbclient -L //172.25.12.12 -U student 以用户身份查看

Screenshot from 2017-12-04 12-32-47.png


[root@station ~]# smbclient //172.25.12.12/student -U student    登录

Screenshot from 2017-12-04 12-38-32.png



*)实现挂载############################

-12主机---

[root@foundation12 yum.repos.d]# yum install samba-client -y 安装服务

[root@desktop ~]# mount -o username=student,password=123 //172.25.12.12/student /mnt/

Screenshot from 2017-12-04 16-01-25.png


*)修改名称########################

[root@station ~]# vim /etc/samba/smb.conf   编辑配置文件


Screenshot from 2017-12-04 16-12-45.png


Screenshot from 2017-12-04 16-13-04.png


[root@station ~]# systemctl restart smb.service  重启服务


Screenshot from 2017-12-04 16-11-44.png[root@station 

更改成功!如下


Screenshot from 2017-12-04 16-17-27.png


*)指定谁登录smb#########################

[root@station ~]# vim /etc/samba/smb.conf  修改配置

Screenshot from 2017-12-04 16-39-08.png


[root@station ~]# systemctl restart smb.service  重启服务


如下10主机登录,250主机不能登录


Screenshot from 2017-12-04 16-40-56.png




*)共享自己的目录#########################

情况1:

[root@station ~]# getenforce   查看火墙状态

[root@station ~]# mkdir /westos  新建目录

Screenshot from 2017-12-04 16-32-35.pngDisabled

[root@station ~]# vim /etc/samba/smb.conf   修改配置文件
Screenshot from 2017-12-04 18-09-03.png

[root@station ~]# systemctl restart smb.service 重启服务


如下,登录可看到自己的目录!

Screenshot from 2017-12-04 18-10-21.png

情况二:

[root@desktop ~]# setenforce 1
[root@desktop ~]# getenforce    
Enforcing

则需要更改安全上下文

[root@desktop ~]# ls -Zd /westos/
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /westos/
[root@desktop ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'
[root@desktop ~]# ls -Zd /westos/
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /westos/
[root@desktop ~]# restorecon -FvvR /westos/
restorecon reset /westos context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file1 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file2 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/file3 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0


挂载


Screenshot from 2017-12-04 18-15-14.png


永久挂载

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

Screenshot from 2017-12-04 18-17-38.png


mount -a 使策略生效


*)匿名用户登陆#######################

[root@station ~]# vim /etc/samba/smb.conf   修改配置文件


Screenshot from 2017-12-04 18-33-42.png


[root@station ~]# systemctl restart smb.service  重启服务

挂载:

[root@desktop ~]# mount //172.25.12.12/DATA /mnt/ -o username=guest,password="" 

   出现错误,由于版本不一样

如下挂载:

[root@desktop ~]# mount //172.25.12.12/DATA /mnt/ -o username=guest  挂载


[root@desktop ~]# smbclient -L /172.25.12.12  匿名登录上


Screenshot from 2017-12-04 18-38-24.png

永久挂载

Screenshot from 2017-12-04 18-41-35.png

*)用户可写########################


Screenshot from 2017-12-04 18-43-22.png


如上不可写!


[root@station ~]# vim /etc/samba/smb.conf 
[root@station ~]# systemctl restart smb.service 


Screenshot from 2017-12-04 18-45-23.png

[root@station ~]# ls -ld /westos/
drwxr-xr-x 2 root root 42 Dec  4 16:18 /westos/   查看权限
[root@station ~]# setfacl -m u:student:rwx /westos/  给用户赋予读写执行权限

Screenshot from 2017-12-04 18-46-54.png

如下,用户可写了

Screenshot from 2017-12-04 18-50-15.png

[root@station ~]# useradd westos  新建用户
[root@station ~]# smbpasswd -a westos  建立smb用户


Screenshot from 2017-12-04 18-52-47.png

[root@station ~]# usermod -G student westos  将用户机入S组
[root@station ~]# setfacl -m g:student:rwx /westos/  赋予组权限


Screenshot from 2017-12-04 18-59-30.png

326         write list = @student   @ / + 为该组


Screenshot from 2017-12-04 19-01-02.png

[root@station ~]# useradd admin  新建用户名字为管理员 可不是真正的管理员 没有管理员的权力

Screenshot from 2017-12-04 19-07-12.png


如下赋予他超户身份


Screenshot from 2017-12-04 19-20-25.png

如下admin可写了!


Screenshot from 2017-12-04 19-22-49.png

*)隐藏共享目录######################


Screenshot from 2017-12-04 19-27-39.png

 browseable = no    默认为yes 隐藏此共享目录(看不到,能用)


Screenshot from 2017-12-04 19-28-46.png


*)指定使用smb用户#########################



Screenshot from 2017-12-04 19-35-03.png

                   vaild users = +student  只有student 组用smb
 

                   vaild users = student   只有student用户用smb


[root@desktop  ~]# mount //172.25.12.12/DATA /mnt/ -o username=admin,password=123
mount error(13): Permission denied                              adimin不能实现挂载了
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)


--smb用户改密码------

[root@station ~]# smbpasswd student   
New SMB password:                 输入新密码
Retype new SMB password:      确认新密码


*)认证##################################


Screenshot from 2017-12-04 19-49-15.png


[root@desktop mnt]# su - kiosk   非smb用户
[kiosk@desktop ~]$ cd /mnt
[kiosk@desktop mnt]$ ls          可看到不安全
file  file1  file2  file3


SMB多用户挂载

(客户机)


Screenshot from 2017-12-04 19-44-45.png

[root@desktop ~]# yum install cifs-utils -y  安装服务

[root@desktop ~]# vim /root/smbfile   编辑文件

Screenshot from 2017-12-04 19-52-12.png


SMB多用户认证

[root@desktop ~]# mount -o credentials=/root/smbfile,multiuser,sec=ntlmssp //172.25.12.12/DATA /mnt


[kiosk@desktop mnt]$ cifscreds add -u westos 172.25.12.12   以smb用户身份查看

Password: 
[kiosk@desktop mnt]$ ls
file  file1  file2  file3  liu
[kiosk@desktop mnt]$ mkdir huan  建立目录


Screenshot from 2017-12-04 20-05-05.png


 本文转自 huanzi2017 51CTO博客,原文链接:http://blog.51cto.com/13362895/2047569


相关文章
|
17天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
70 1
|
20天前
|
Linux 数据安全/隐私保护 Windows
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
Linux入门指南:linux权限究竟是什么?和文件有什么关系?
30 0
|
22天前
|
算法 Linux C++
【Linux系统编程】解析获取和设置文件信息与权限的Linux系统调用
【Linux系统编程】解析获取和设置文件信息与权限的Linux系统调用
29 0
|
26天前
|
Shell Linux API
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
47 0
|
15天前
|
人工智能 安全 Linux
【Linux】Linux之间如何互传文件(详细讲解)
【Linux】Linux之间如何互传文件(详细讲解)
|
26天前
|
Shell Linux C语言
【Shell 命令集合 系统设置 】Linux 创建Kickstart文件mkkickstart命令 使用指南
【Shell 命令集合 系统设置 】Linux 创建Kickstart文件mkkickstart命令 使用指南
31 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
28 0
|
26天前
|
安全 Shell Linux
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
35 0
|
26天前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
48 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 备份压缩 】Linux 恢复由dump命令创建的备份文件 restore命令 使用指南
【Shell 命令集合 备份压缩 】Linux 恢复由dump命令创建的备份文件 restore命令 使用指南
31 0