Samba实现Windows与Linux之间的文件共享

注:这里只是个人笔记,不具备参考价值

1.安装samba

[root@linuxprobe ~]# yum install samba
............
Installed:
  samba.x86_64 0:3.6.23-46el6_9                                                                                                                                          

Dependency Updated:
libsmbclient.x86_64 0:3.6.23-46el6_9            
samba-client.x86_64 0:3.6.23-46el6_9   
samba-common.x86_64 0:3.6.23-46el6_9   
samba-winbind.x86_64 0:3.6.23-46el6_9  
samba-winbind-clients.x86_64 0:3.6.23-46el6_9  

Complete!

2.整理配置文件

主要是为了去除不必要的注释信息

[root@linuxprobe ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@linuxprobe ~]# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
[root@linuxprobe ~]# cat /etc/samba/smb.conf

3.配置共享资源

一些配置参数:


Samba实现Windows与Linux之间的文件共享_第1张图片

3.1 创建用于访问共享资源的账户信息

pdbedit 命令用于管理 SMB 服务程序的账户信息数据库,格式为“pdbedit [选项] 账户”。在第一次把账户信息写入到数据库时需要使用-a 参数,以后在执行修改密码、删除账户等操作时就不再需要该参数了。 pdbedit 命令中使用的参数以及作用如表所示:


Samba实现Windows与Linux之间的文件共享_第2张图片
[root@linuxprobe ~]# id linuxprobe
uid=1000(linuxprobe) gid=1000(linuxprobe) groups=1000(linuxprobe)
[root@linuxprobe ~]# pdbedit -a -u linuxprobe
new password: 此处输入该账户在Samba数据库中的密码
retype new password:再次输入该账户在Samba数据库中的密码
Unix username: linuxprobe
NT username:
Account Flags:
User SID: S-1-5-21-507407404-3243012849-3065158664-1000
Primary Group SID: S-1-5-21-507407404-3243012849-3065158664-513
Full Name: linuxprobe
Home Directory: \\localhost\linuxprobe
HomeDir Drive:
Logon Script:
Profile Path: \\localhost\linuxprobe\profile
Domain: LOCALHOST
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 10:06:39 EST
Kickoff time: Wed, 06 Feb 2036 10:06:39 EST
Password last set: Mon, 13 Mar 2017 04:22:25 EDT
Password can change: Mon, 13 Mar 2017 04:22:25 EDT
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

3.2 创建用于共享资源的文件目录

[root@linuxprobe ~]# mkdir /home/database
[root@linuxprobe ~]# chown -Rf linuxprobe:linuxprobe /home/database
[root@linuxprobe ~]# semanage fcontext -a -t samba_share_t /home/database
[root@linuxprobe ~]# restorecon -Rv /home/database
restorecon reset /home/database context unconfined_u:object_r:home_root_t:s0->
unconfined_u:object_r:samba_share_t:s0

3.4 设置 SELinux 服务与策略

[root@linuxprobe ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@linuxprobe ~]# setsebool -P samba_enable_home_dirs on

3.5 配置Samba主配置文件

[root@linuxprobe ~]# vim /etc/samba/smb.conf
1 [global]
2 workgroup = MYGROUP
3 server string = Samba Server Version %v
4 log file = /var/log/samba/log.%m
5 max log size = 50
6 security = user
7 passdb backend = tdbsam
8 load printers = yes
9 cups options = raw
10 [database]
11 comment = Do not arbitrarily modify the database file
12 path = /home/database
13 public = no
14 writable = yes

3.6重启 smb 服务

[root@linuxprobe ~]# systemctl restart smb
[root@linuxprobe ~]# systemctl enable smb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.
target.wants/smb.service'
[root@linuxprobe ~]# iptables -F
[root@linuxprobe ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

4.Windows 访问文件共享服务

打开电脑,按住win+R组合键,输入samba服务器的地址,如下:

Samba实现Windows与Linux之间的文件共享_第3张图片

或按照如下方式:

Samba实现Windows与Linux之间的文件共享_第4张图片

5.Linux访问文件共享服务

不但windows可以访问搭建好的samba服务,linux之间也可以访问

5.1安装cifs-utils

[root@linuxprobe ~]# yum install cifs-utils
Loaded plugins: langpacks, product-id, subscription-manager
rhel | 4.1 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0:6.2-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
cifs-utils x86_64 6.2-6.el7 rhel 83 k
Transaction Summary
===============================================================================
Install 1 Package
Total download size: 83 k
Installed size: 174 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : cifs-utils-6.2-6.el7.x86_64 1/1
Verifying : cifs-utils-6.2-6.el7.x86_64 1/1
Installed:
cifs-utils.x86_64 0:6.2-6.el7
Complete!

5.2 配置登录信息

[root@linuxprobe ~]# vim auth.smb
username=linuxprobe
password=redhat
domain=MYGROUP
[root@linuxprobe ~]# chmod 600 auth.smb

5.3 挂载远程文件夹

[root@linuxprobe ~]# mkdir /database
[root@linuxprobe ~]# vim /etc/fstab
# #
/etc/fstab
# Created by anaconda on Wed May 4 19:26:23 2017
# #
Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2
/dev/mapper /rhel-swap swap swap defaults 0 0
/dev/cdrom /media/cdrom iso9660 defaults 0 0
#下面这行是关键
//192.168.10.10/database /database cifs credentials=/root/auth.smb 0 0
[root@linuxprobe ~]# mount -a

你可能感兴趣的:(Samba实现Windows与Linux之间的文件共享)