Ubuntu-16.04.1搭建Samba服务器

应用场景:很多哥们在Linux系统上开发应用多多少少遇到相似情况,基本都是虚拟机搭个Ubuntu环境,开个共享目录进行一些文件和代码共享,但共享目录并不是真实的Linux环境,对于一些操作是无法进行的,比如不能创建软链接,不区分文件大小写,或解压.gz文件时出现一些链接错误等。为给我们苦逼的Linux应用开发者提供一个真正的Linux环境又能实现Windows共享,那就搭建个samba服务器吧。

1:使用apt-get安装

sudo apt-get install samba

2:检查samba是否安装好

qiuhui@ubuntu:~$ samba
[2019/12/29 15:44:02.217215,  0] ../lib/util/debug.c:947(reopen_logs_internal)
  Unable to open new log file '/var/log/samba/log.%m': Permission denied
[2019/12/29 15:44:02.217287,  0] ../source4/smbd/server.c:372(binary_smbd_main)
  samba version 4.3.11-Ubuntu started.
  Copyright Andrew Tridgell and the Samba Team 1992-2015
qiuhui@ubuntu:~$ samba -V
Version 4.3.11-Ubuntu
qiuhui@ubuntu:~$ 

注:有以上log证明已安装完成了

3:配置samba匿名访问(Anonymous share)

注:配置前建议先备份下smb.conf

qiuhui@ubuntu:~$ ls -l /etc/samba/smb.conf 
-rw-r--r-- 1 root root 9542 Dec 29 11:50 /etc/samba/smb.conf
qiuhui@ubuntu:~$ sudo cp -rf /etc/samba/smb.conf /etc/samba/smb.conf.bak
[sudo] password for qiuhui: 
qiuhui@ubuntu:~$ ls -l /etc/samba/
total 32
-rw-r--r-- 1 root root    8 Nov 30 03:03 gdbcommands
-rw-r--r-- 1 root root 9542 Dec 29 11:50 smb.conf
-rw-r--r-- 1 root root 9542 Dec 29 15:50 smb.conf.bak
drwxr-xr-x 2 root root 4096 Nov 30 03:02 tls
qiuhui@ubuntu:~$ 

一:创建共享目录并打开配置文件
qiuhui@ubuntu:/etc/samba$ mkdir /home/qiuhui/work/share
qiuhui@ubuntu:/etc/samba$ sudo vi /etc/samba/smb.conf
二:在配置文件末尾追加以下内容:

[Anonymous share]
comment = this is Linux share directory (Anonymous)
#共享目录的位置
path = /home/qiuhui/work/share
#表示是否可以在 Window Explorer中显示该目录
browsable = yes
#表示是否允许匿名访问该共享目录
public = yes
#表示是否是只读
writable = yes
#read only = no
#指明新建立的文件的属性
create mask = 0777
#指明新建立的目录的属性
directory mask = 0777

三:测试下刚刚的配置文件是否有效(此步骤可有可无)
qiuhui@ubuntu:/etc/samba$ testparm /etc/samba/smb.conf
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[printers]"
Processing section "[print$]"
Processing section "[Anonymous share]"
Loaded services file OK.
WARNING: You have some share names that are longer than 12 characters.
These may not be accessible to some older clients.
(Eg. Windows9x, WindowsMe, and smbclient prior to Samba 3.0.)
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
	server string = %h server (Samba, Ubuntu)
	server role = standalone server
	map to guest = Bad User
	obey pam restrictions = Yes
	pam password change = Yes
	passwd program = /usr/bin/passwd %u
	passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
	unix password sync = Yes
	syslog = 0
	log file = /var/log/samba/log.%m
	max log size = 1000
	dns proxy = No
	usershare allow guests = Yes
	panic action = /usr/share/samba/panic-action %d
	idmap config * : backend = tdb


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


[print$]
	comment = Printer Drivers
	path = /var/lib/samba/printers


[Anonymous share]
	comment = this is Linux share directory (Anonymous)
	path = /home/qiuhui/work/share
	read only = No
	create mask = 0777
	directory mask = 0777
	directory mode = 0777
	guest ok = Yes
qiuhui@ubuntu:/etc/samba$ 

四:重新启动samba
qiuhui@ubuntu:/etc/samba$ sudo service smbd restart
五:windows10访问samba共享目录,如下图

在这里插入图片描述

4:配置samba用户访问(User+Password share)

一:创建一个共享目录
qiuhui@ubuntu:/etc/samba$ mkdir /home/qiuhui/work/share
二:创建一个“XXXX”用户用于访问samba,这里就直接用我“qiuhui”用户了,不再新建新用户了
三:在配置文件末尾追加以下内容:

[User share]
comment = this is Linux share directory
#共享目录的位置
path = /home/qiuhui/work/share
#表示是否可以在 Window Explorer中显示该目录
browsable = yes
#表示是否允许匿名访问该共享目录
public = no
#表示是否是只读
writable = yes
#read only = no
#指明新建立的文件的属性
create mask = 0777
#指明新建立的目录的属性
directory mask = 0777
#指明可以访问的用户
valid user = qiuhui

四:将用户 “qiuhui”加入到 smbpasswd file
qiuhui@ubuntu:/etc/samba$ sudo smbpasswd -a qiuhui
New SMB password:
Retype new SMB password:
qiuhui@ubuntu:/etc/samba$
五:重新启动samba
qiuhui@ubuntu:/etc/samba$ sudo service smbd restart
六:windows10输入用户名+密码访问samba共享目录,如下图

在这里插入图片描述
在这里插入图片描述
注:访问如果出现“不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接”的提示,请使用doc窗口执行以下命令后再执行上面第六个步骤不会有这个提示了
window访问samba共享的文件夹没有写权限请双击!!!在这里插入图片描述

结语:本文只介绍简单的samba服务器搭建,像共享用户映射等等其他一些配置就不记录了,因为我也没配置,哈哈哈哈

发布了7 篇原创文章 · 获赞 4 · 访问量 654

猜你喜欢

转载自blog.csdn.net/qq_15762939/article/details/103754265