今天学习了 Samba 服务配置, Samba 服务可以用来实现 windows 和 Linux
实现目录共享,本文
简单介绍下 RHEL6 环境下配置 Samba 服务的过程,
一 安装 samba 服务
--1.1 Samba 需要安装的包
samba
samba-common
samba-client
--1.2 查看已安装的 samba 相关包
[root@redhat6 samba]# rpm -qa | grep
samba samba-common-3.5.10-114.el6.i686 samba-winbind-clients-3.5.10-114.el6.i686 samba-client-3.5.10-114.el6.i686 |
备注:系统上还少了 samba 包,接下来需要安装这个包。
--1.3 安装 samba 包
[root@redhat6 samba]# yum search samba Loaded plugins: product-id, refresh-packagekit, security, subscription-manager Updating certificate-based repositories. Repository rhel-source is listed more than once in the configuration ======================================================== N/S Matched: samba ======================================================== samba-client.i686 : Samba client programs samba-common.i686 : Files used by both Samba servers and clients samba-winbind.i686 : Samba winbind samba-winbind-clients.i686 : Samba winbind clients sblim-cmpi-samba.i686 : SBLIM WBEM-SMT Samba ctdb.i686 : A Clustered Database based on Samba's Trivial Database (TDB) samba.i686 : Server and Client software to interoperate with Windows machines Name and summary matches only, use "search all" for
everything. Dependencies Resolved ==================================================================================================================================== Transaction
Summary Total download size: 5.0 M Installed: Complete! |
--1.4 Samba的端口
Nmbd:
137 138
smbd: tcp 139 445
备注:修改防火墙配置,打开 tcp 139,445 端口。
二 以匿名方式配置 samba
--2.1 配置 samba 配置文件
修改文件
/etc/samba/smb.conf, 修改 security 参数,部分内容如下
[global] security = share passdb backend = tdbsam #============================ Share Definitions
============================== |
备注:当 security 配置成 share 时,访问共享目录不需要输入密码。
--2.2
共享目录相关参数说明
comment: 共享目录备注
path:
设置共享目录
public: 设置共享目录是否支持匿名访问
browseable:
设置用户是否可以在浏览器中看到目录
writeable: 设置用户是否可以在共享目录写入数据
valid user:
设置哪些用户可以访问共享目录
create mode: 设置用户在共享目录里创建文件的默认权限
directory mode:
设置用户在共享目录里创建文件夹的默认权限
--2.3
创建目录
[root@redhat6 /]# mkdir -p
/francs_share
[root@redhat6 /]# chmod -R 777 /francs_share
--2.4 查看 seliniux
运行模式
[root@redhat6 /]# getenforce
Enforcing
--2.5 测试
在运行中输入
”\\192.168.1.35\” 可以看到共享目录,如图所示
备注:
但是不能进入共享目录,双击目录时,报以下ERROR
原因是,RHEL6的selinux 挡住了,解决方法有两种: 1
禁用
selinux
2 配置 selinux
--2.6
方法一:禁用 selinux
[root@redhat6 samba]#
getenforce
Enforcing
[root@redhat6 samba]# setenforce 0
[root@redhat6
samba]# getenforce
Permissive
--2.7 方法二:配置 selinux
--配置文件属性
,给共享目录加上标签
[root@redhat6 francs_share]# semanage fcontext -a
-t samba_share_t "/francs_share(/.*)?"
备注: smbd 服务可以对拥有具有 samba_share_1 属性的文件进行读写。
--使标签生效
[root@redhat6 francs_share]# restorecon -R -v
/francs_share/
restorecon reset /francs_share context
unconfined_u:object_r:default_t:s0->unconfined_u:object_r:samba_share_t:s0
--重启 smb 服务
[root@redhat6 samba]# service smb
restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK
]
--2.8 再次访问测试
配置好
selinux 后,可以进入共享目录 /francs_share ,并查看其中的子文件了。
三 以输入用户名/密码方式配置 samba 服务
--3.1 配置 samba 配置文件
修改文件
/etc/samba/smb.conf 的 security 参数,部分内容如下
[global] security = user passdb backend = tdbsam #============================ Share Definitions
============================== |
备注:修改参数 security = user 参数。
--3.2 增加用户 user2
[root@redhat6 ~]# useradd user2 [root@redhat6 ~]# passwd user2 Changing password for user user2. New password: Retype new password: passwd: all authentication tokens updated successfully. |
--3.3 设置 samba 用户 user2
密码
[root@redhat6 ~]# smbpasswd -a user2 New SMB password: Retype new SMB password: Added user user2. [root@redhat6 ~]# |
备注:这个密码是在 windows 平台上访问 Linux 共享目录的密码。
--3.4 查看共享目录信息
[root@redhat6 ~]# smbclient -U user2 -L localhost Enter user2's password: Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.5.10-114.el6] Sharename Type Comment Server Comment Workgroup Master |
--3.5 重启 smb 服务
[root@redhat6 samba]# service
smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [
OK ]
--3.6 连接测试
访问成功,如图所示
备注:在上图输入用户名和密码后,就可以访问目录 /francs_share,,并可在此目录进行创建,***文件。
四 常见问题
学习samba的时候,尝试用windows XP 连接 Linux
当一个用户登录成功后,想再试试其他用户能否成功
登录就会提示不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接,这时需要断掉当前用户
重新登录,步骤如下。
--Windows 机器执行 net 命令
C:\Documents and Settings\ThinkPad>net use * /del /y 您有以下的远程连接: \\192.168.1.35\myshare 命令成功完成。 |