centos7安装samba服务器

centos7安装samba服务器,这是一种比较粗暴的配置方式,没有任何安全防御措施,任何人都可以访问服务器上的文件,并且没有权限设置,这样做的目的就是方便Windows和Linux之间传输文件使用,简单记录一下搭建的过程

一.安装
[root@localhost ~]# yum -y install samba samba-client samba-common
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

  • base: mirror.bit.edu.cn
  • extras: mirrors.btte.net
  • updates: mirrors.btte.net
    Resolving Dependencies
    --> Running transaction check
    ---> Package samba.x86_64 0:4.4.4-14.el7_3 will be installed
    --> Processing Dependency: samba-libs = 4.4.4-14.el7_3 for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: samba-common-tools = 4.4.4-14.el7_3 for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: samba-common-libs = 4.4.4-14.el7_3 for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: samba-client-libs = 4.4.4-14.el7_3 for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: libwbclient = 4.4.4-14.el7_3 for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.4.4)(64bit) for package: samba-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for package: samba-4.4.4-14.el7_3.x86_64
    ---> Package samba-client.x86_64 0:4.4.4-9.el7 will be updated
    ---> Package samba-client.x86_64 0:4.4.4-14.el7_3 will be an update
    --> Processing Dependency: libsmbclient = 4.4.4-14.el7_3 for package: samba-client-4.4.4-14.el7_3.x86_64
    ---> Package samba-common.noarch 0:4.4.4-9.el7 will be updated
    ---> Package samba-common.noarch 0:4.4.4-14.el7_3 will be an update
    --> Running transaction check
    ---> Package libsmbclient.x86_64 0:4.4.4-9.el7 will be updated
    ---> Package libsmbclient.x86_64 0:4.4.4-14.el7_3 will be an update
    ---> Package libwbclient.x86_64 0:4.4.4-9.el7 will be updated
    ---> Package libwbclient.x86_64 0:4.4.4-14.el7_3 will be an update
    ---> Package samba-client-libs.x86_64 0:4.4.4-9.el7 will be updated
    ---> Package samba-client-libs.x86_64 0:4.4.4-14.el7_3 will be an update
    ---> Package samba-common-libs.x86_64 0:4.4.4-9.el7 will be updated
    ---> Package samba-common-libs.x86_64 0:4.4.4-14.el7_3 will be an update
    ---> Package samba-common-tools.x86_64 0:4.4.4-14.el7_3 will be installed
    ---> Package samba-libs.x86_64 0:4.4.4-14.el7_3 will be installed
    --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit) for package: samba-libs-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit) for package: samba-libs-4.4.4-14.el7_3.x86_64
    --> Processing Dependency: libpytalloc-util.so.2()(64bit) for package: samba-libs-4.4.4-14.el7_3.x86_64
    --> Running transaction check
    ---> Package pytalloc.x86_64 0:2.1.6-1.el7 will be installed
    --> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
samba x86_64 4.4.4-14.el7_3 updates 610 k
Updating:
samba-client x86_64 4.4.4-14.el7_3 updates 547 k
samba-common noarch 4.4.4-14.el7_3 updates 191 k
Installing for dependencies:
pytalloc x86_64 2.1.6-1.el7 base 15 k
samba-common-tools x86_64 4.4.4-14.el7_3 updates 451 k
samba-libs x86_64 4.4.4-14.el7_3 updates 260 k
Updating for dependencies:
libsmbclient x86_64 4.4.4-14.el7_3 updates 126 k
libwbclient x86_64 4.4.4-14.el7_3 updates 100 k
samba-client-libs x86_64 4.4.4-14.el7_3 updates 4.6 M
samba-common-libs x86_64 4.4.4-14.el7_3 updates 161 k

Transaction Summary

Install 1 Package (+3 Dependent packages)
Upgrade 2 Packages (+4 Dependent packages)

Total download size: 7.0 M
Downloading packages:
updates/7/x86_64/prestodelta | 954 kB 00:00:00
Delta RPMs reduced 5.4 M of updates to 553 k (90% saved)
(1/10): libsmbclient-4.4.4-9.el7_4.4.4-14.el7_3.x86_64.drpm | 76 kB 00:00:00
(2/10): samba-client-libs-4.4.4-9.el7_4.4.4-14.el7_3.x86_64.drpm | 261 kB 00:00:00
(3/10): samba-common-libs-4.4.4-9.el7_4.4.4-14.el7_3.x86_64.drpm | 77 kB 00:00:00
warning: /var/cache/yum/x86_64/7/updates/packages/libwbclient-4.4.4-14.el7_3.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for libwbclient-4.4.4-14.el7_3.x86_64.rpm is not installed
(4/10): libwbclient-4.4.4-14.el7_3.x86_64.rpm | 100 kB 00:00:00
Public key for pytalloc-2.1.6-1.el7.x86_64.rpm is not installed
(5/10): pytalloc-2.1.6-1.el7.x86_64.rpm | 15 kB 00:00:00
(6/10): samba-4.4.4-14.el7_3.x86_64.rpm | 610 kB 00:00:00
(7/10): samba-common-4.4.4-14.el7_3.noarch.rpm | 191 kB 00:00:00
(8/10): samba-common-tools-4.4.4-14.el7_3.x86_64.rpm | 451 kB 00:00:00
(9/10): samba-libs-4.4.4-14.el7_3.x86_64.rpm | 260 kB 00:00:00
(10/10): samba-client-4.4.4-9.el7_4.4.4-14.el7_3.x86_64.drpm | 139 kB 00:00:05
Finishing delta rebuilds of 1 package(s) (547 k)


Total 351 kB/s | 2.1 MB 00:00:06
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) security@centos.org"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : samba-common-4.4.4-14.el7_3.noarch 1/16
Updating : libwbclient-4.4.4-14.el7_3.x86_64 2/16
Updating : samba-client-libs-4.4.4-14.el7_3.x86_64 3/16
Updating : samba-common-libs-4.4.4-14.el7_3.x86_64 4/16
Updating : libsmbclient-4.4.4-14.el7_3.x86_64 5/16
Installing : pytalloc-2.1.6-1.el7.x86_64 6/16
Installing : samba-libs-4.4.4-14.el7_3.x86_64 7/16
Installing : samba-common-tools-4.4.4-14.el7_3.x86_64 8/16
Installing : samba-4.4.4-14.el7_3.x86_64 9/16
Updating : samba-client-4.4.4-14.el7_3.x86_64 10/16
Cleanup : samba-client-4.4.4-9.el7.x86_64 11/16
Cleanup : samba-common-libs-4.4.4-9.el7.x86_64 12/16
Cleanup : libsmbclient-4.4.4-9.el7.x86_64 13/16
Cleanup : libwbclient-4.4.4-9.el7.x86_64 14/16
Cleanup : samba-client-libs-4.4.4-9.el7.x86_64 15/16
Cleanup : samba-common-4.4.4-9.el7.noarch 16/16
Verifying : samba-common-libs-4.4.4-14.el7_3.x86_64 1/16
Verifying : samba-client-4.4.4-14.el7_3.x86_64 2/16
Verifying : samba-4.4.4-14.el7_3.x86_64 3/16
Verifying : samba-client-libs-4.4.4-14.el7_3.x86_64 4/16
Verifying : libsmbclient-4.4.4-14.el7_3.x86_64 5/16
Verifying : samba-libs-4.4.4-14.el7_3.x86_64 6/16
Verifying : samba-common-tools-4.4.4-14.el7_3.x86_64 7/16
Verifying : samba-common-4.4.4-14.el7_3.noarch 8/16
Verifying : pytalloc-2.1.6-1.el7.x86_64 9/16
Verifying : libwbclient-4.4.4-14.el7_3.x86_64 10/16
Verifying : samba-client-libs-4.4.4-9.el7.x86_64 11/16
Verifying : libsmbclient-4.4.4-9.el7.x86_64 12/16
Verifying : samba-common-4.4.4-9.el7.noarch 13/16
Verifying : samba-common-libs-4.4.4-9.el7.x86_64 14/16
Verifying : libwbclient-4.4.4-9.el7.x86_64 15/16
Verifying : samba-client-4.4.4-9.el7.x86_64 16/16

Installed:
samba.x86_64 0:4.4.4-14.el7_3

Dependency Installed:
pytalloc.x86_64 0:2.1.6-1.el7 samba-common-tools.x86_64 0:4.4.4-14.el7_3
samba-libs.x86_64 0:4.4.4-14.el7_3

Updated:
samba-client.x86_64 0:4.4.4-14.el7_3 samba-common.noarch 0:4.4.4-14.el7_3

Dependency Updated:
libsmbclient.x86_64 0:4.4.4-14.el7_3 libwbclient.x86_64 0:4.4.4-14.el7_3
samba-client-libs.x86_64 0:4.4.4-14.el7_3 samba-common-libs.x86_64 0:4.4.4-14.el7_3

Complete!
二.修改配置
[root@localhost ~]# cd /etc/samba/
[root@localhost samba]# ll
total 20
-rw-r--r--. 1 root root 20 May 25 04:33 lmhosts
-rw-r--r--. 1 root root 667 May 25 04:33 smb.conf
-rw-r--r--. 1 root root 11327 May 25 04:33 smb.conf.example
还是先备份一下比较好,毕竟本服务区配置的比较暴力
[root@localhost samba]# cp smb.conf smb_back,conf
原始配置文件内容
[root@localhost samba]# cat smb.conf

See smb.conf.example for a more detailed config file or

read the smb.conf manpage.

Run 'testparm' to verify the config is correct after

you modified it.

[global]
workgroup = SAMBA
security = user

passdb backend = tdbsam

printing = cups
printcap name = cups
load printers = yes
cups options = raw

[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes

[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No

[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = root
create mask = 0664
directory mask = 0775

配置的比较简单粗暴,不设置任何用户,密码的限制,只设置访问的目录为根目录
[root@bogon samba]# vim smb.conf
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
[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
[myshare]
comment = myshare
path = /
writable = yes
三.添加用户
1.添加Linux用户
[root@bogon ~]# useradd myshare
[root@bogon ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:997:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
unbound:x:997:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
libstoragemgmt:x:996:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
colord:x:995:993:User for colord:/var/lib/colord:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin
geoclue:x:993:991:User for geoclue:/var/lib/geoclue:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
chrony:x:992:989::/var/lib/chrony:/sbin/nologin
setroubleshoot:x:991:988::/var/lib/setroubleshoot:/sbin/nologin
sssd:x:990:987:User for sssd:/:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:989:984::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
kongs:x:1000:1000:centos7:/home/kongs:/bin/bash
myshare:x:1001:1001::/home/myshare:/bin/bash

添加samba用户,samba用户必须为Linux用户,否则添加不上
[root@bogon ~]# pdbedit -a myshare
retype new password:
new password: //未设置密码
Unix username: myshare
NT username:
Account Flags: [U ]
User SID: S-1-5-21-178771426-1853948353-1867861984-1001
Primary Group SID: S-1-5-21-178771426-1853948353-1867861984-513
Full Name:
Home Directory: \bogonmyshare
HomeDir Drive:
Logon Script:
Profile Path: \bogonmyshareprofile
Domain: BOGON
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 07:06:39 PST
Kickoff time: Wed, 06 Feb 2036 07:06:39 PST
Password last set: Fri, 18 Aug 2017 01:10:03 PDT
Password can change: Fri, 18 Aug 2017 01:10:03 PDT
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
四.重启服务
[root@localhost samba]# systemctl restart nmb
[root@localhost samba]# systemctl restart smb
[root@localhost samba]# ps -ef | grep nmb
root 13192 1 0 19:48 ? 00:00:00 /usr/sbin/nmbd
root 13304 12809 0 19:49 pts/1 00:00:00 grep --color=auto nmb
五.关闭防火墙
[root@bogon ~]# systemctl stop firewalld
[root@bogon ~]# systemctl status firewalld
бё firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2017-08-09 20:04:24 PDT; 2s ago
Docs: man:firewalld(1)
Process: 610 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 610 (code=exited, status=0/SUCCESS)

Aug 09 20:03:16 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Aug 09 20:03:17 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Aug 09 20:04:24 bogon systemd[1]: Stopping firewalld - dynamic firewall daemon...
Aug 09 20:04:24 bogon systemd[1]: Stopped firewalld - dynamic firewall daemon.

六.客户端连接

说明:尽量不要使用root用户作为samba用户,否则在Windows下写权限会受到限制,需要修改selinux等,这样反而麻烦了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,386评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,142评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,704评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,702评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,716评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,573评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,314评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,230评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,680评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,873评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,991评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,706评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,329评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,910评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,038评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,158评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,941评论 2 355

推荐阅读更多精彩内容