Linux系统Samba文件共享服务

本文详细介绍了Samba服务器的安装过程、配置步骤及测试方法。主要内容包括:安装所需软件包、配置smb.conf文件实现资源共享、创建Samba用户账号、添加公共目录、测试配置文件的有效性以及启动Samba服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Samba服务器的安装

确认安装以下软件包

[root@test ~]# rpm -qa|grep samba
samba-common-3.0.10-1.4E.9
samba-client-3.0.10-1.4E.9
system-config-samba-1.2.21-1
samba-swat-3.0.10-1.4E.9
samba-3.0.10-1.4E.9

 

二、Samba服务器的配置步骤

1.在smb.conf 文件中进行共享资源的配置,包括用户目录、公共目录等。

2.使用smbpasswd 命令建立Samba 用户账号和设置账号密码。

3.使用testparm命令测试 smb.conf 配置文件。

4.使用smb 脚本启动Samba服务器。

 

三、smb.conf 文件的配置

1.认识smb.conf 文件:Samba服务器的主配置文件是smb.conf ,保存在“/etc/samba/”中。

[root@test ~]# head -5 /etc/samba/smb.conf
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
[root@test ~]# tail /etc/samba/smb.conf
;[myshare]
;   comment = Mary's and Fred's stuff
;   path = /usr/somewhere/shared
;   valid users = mary fred
;   public = no
;   writable = yes
;   printable = no
;   create mask = 0765

 

2.如果只需要查看 smb.conf 配置文件中的有效配置项,可以去除所有的注释行和样例行,使用的命令如下:

[root@test ~]# grep -v "^#" /etc/samba/smb.conf |grep -v "^;"
[global]

   workgroup = MYGROUP

   server string = Samba Server


   printcap name = /etc/printcap
   load printers = yes


   cups options = raw


   log file = /var/log/samba/%m.log

   max log size = 50

   security = user


   socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192

 


   dns proxy = no


   idmap uid = 16777216-33554431
   idmap gid = 16777216-33554431
   template shell = /bin/false
   winbind use default domain = no
[homes]
   comment = Home Directories
   browseable = no
   writable = yes

 

 

[printers]
   comment = All Printers
   path = /var/spool/samba
   browseable = no
   guest ok = no
   writable = no
   printable = yes

 

 

四、建立Samba用户账号

[root@test ~]# useradd st02
[root@test ~]# smbpasswd -a st02
New SMB password:
Retype new SMB password:
startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created.
Added user st02.
[root@test ~]# cat /etc/samba/smbpasswd
st02:500:E8450C7E07112982AAD3B435B51404EE:2D7F1A5A61D3A96FB5159B5EEF17ADC6:[U          ]:LCT-49ED664B:

 

smbpasswd后面可以跟其它参数,如:
u       -h 显示smbpasswd的命令格式帮助
u       -a 添加指定的用户账号
u       -d 禁用指定的用户账号
u       -e 启动指定的用户账号
u       -x 删除指定的用户账号
u       不使用任何命令选项时将更改用户口令。

五、添加公共目录

在smb.conf 文件中添加名为[public]的共享资源,并设置如下内容:

[public]
   path = /home/testpublic
   public = yes
   only guest = yes
   writable = yes

 

六、测试smb.conf 文件配置

[root@test home]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[public]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

# Global parameters
[global]
        workgroup = MYGROUP
        server string = Samba Server
        log file = /var/log/samba/%m.log
        max log size = 50
        socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
        printcap name = /etc/printcap
        os level = 33
        dns proxy = No
        idmap uid = 16777216-33554431
        idmap gid = 16777216-33554431
        cups options = raw

[homes]
        comment = Home Directories
        read only = No
        browseable = No

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        browseable = No

[public]
        path = /home/testpublic
        read only = No
        guest only = Yes
        guest ok = Yes

七、启动Samba服务器


[root@test home]# service smb start

 

1.         service smb start  启动Samba服务
2.         service smb status 查看samba服务状态
3.         service smb stop  停止samba服务

 

八、利用WINDOWS // ip 测试访问samba服务器

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值