日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Samba 服务共享

發(fā)布時(shí)間:2023/12/20 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Samba 服务共享 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

linux下配置samba服務(wù)器
1、 什么是samba
Samba服務(wù)類似于windows上的共享功能,可以實(shí)現(xiàn)在Linux上共享文件,windows上訪問(wèn),當(dāng)然在Linux上也可以訪問(wèn)到。
是一種在局域網(wǎng)上共享文件和打印機(jī)的一種通信協(xié)議,它為局域網(wǎng)內(nèi)的不同計(jì)算機(jī)之間提供文件及打印機(jī)等資源的共享服務(wù)。

2、安裝配置samba
安裝命令:yum install -y samba samba-client

[root@samba-server ~]# egrep -v "^$|#|;" /etc/samba/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

1.配置文件解釋:
[global] 定義全局的配置,workgroup用來(lái)定義工作組,相信如果您安裝過(guò)windows的系統(tǒng),你會(huì)對(duì)這個(gè)workgroup不陌生。一般情況下,需要我們把這里的MYGROUP改成WORKGROUP(windows默認(rèn)的工作組名字)。
security = user #這里指定samba的安全等級(jí)。
關(guān)于安全等級(jí)有四種:
share:用戶不需要賬戶及密碼即可登錄samba服務(wù)器
user:由提供服務(wù)的samba服務(wù)器負(fù)責(zé)檢查賬戶及密碼(默認(rèn))
server:檢查賬戶及密碼的工作由另一臺(tái)windows或samba服務(wù)器負(fù)責(zé)
domain:指定windows域控制服務(wù)器來(lái)驗(yàn)證用戶的賬戶及密碼。
passdb backend = tdbsam #passdb backend(用戶后臺(tái))
samba有三種用戶后臺(tái):smbpasswd, tdbsam和ldapsam。
load printers:加載打印機(jī)
cups options = raw 打印機(jī)相關(guān)設(shè)置;

2.samba配置文件參數(shù)介紹

smbpasswd:該方式是使用smb工具smbpasswd給系統(tǒng)用戶(真實(shí)用戶或者虛擬用戶)設(shè)置一個(gè)Samba密碼,客戶端就用此密碼訪問(wèn)Samba資源。smbpasswd在/etc/samba中,有時(shí)需要手工創(chuàng)建該文件。
tdbsam: 使用數(shù)據(jù)庫(kù)文件創(chuàng)建用戶數(shù)據(jù)庫(kù)。數(shù)據(jù)庫(kù)文件叫passdb.tdb,在/etc/samba中。passdb.tdb用戶數(shù)據(jù)庫(kù)可使用 smbpasswd -a 創(chuàng)建Samba用戶,要?jiǎng)?chuàng)建的Samba用戶必須先是系統(tǒng)用戶。也可使用pdbedit創(chuàng)建Samba賬戶。
pdbedit參數(shù)很多,列出幾個(gè)主要的:
pdbedit -a username:新建Samba賬戶。
pdbedit -x username:刪除Samba賬戶。
pdbedit -L:列出Samba用戶列表,讀取passdb.tdb數(shù)據(jù)庫(kù)文件。
pdbedit -Lv:列出Samba用戶列表詳細(xì)信息。
pdbedit -c “[D]” -u username:暫停該Samba用戶賬號(hào)。
pdbedit -c “[]” -u username:恢復(fù)該Samba用戶賬號(hào)。
ldapsam:基于LDAP賬戶管理方式驗(yàn)證用戶。首先要建立LDAP服務(wù),設(shè)置 “passdb backend = ldapsam:ldap://LDAP Server”
load printers 和 cups options 兩個(gè)參數(shù)用來(lái)設(shè)置打印機(jī)相關(guān)。
除了這些參數(shù)外,還有幾個(gè)參數(shù)需要你了解:
netbios name = MYSERVER # 設(shè)置出現(xiàn)在網(wǎng)上鄰居中的主機(jī)名
hosts allow = 127. 192.168.12. 192.168.13. 172.16.# 用來(lái)設(shè)置允許的主機(jī),如果在前面加 ”;” 則表示允許所有主機(jī)
log file = /var/log/samba/%m.log #定義samba的日志,這里的%m是上面的netbios name
max log size = 50 # 指定日志的最大容量,單位是K
[homes] 該部分內(nèi)容共享用戶自己的家目錄,也就是說(shuō),當(dāng)用戶登錄到samba服務(wù)器上時(shí)實(shí)際上是進(jìn)入到了該用戶的家目錄,用戶登陸后,共享名不是homes而是用戶自己的標(biāo)識(shí)符,對(duì)于單純的文件共享的環(huán)境來(lái)說(shuō),這部分可以注視掉。
[printers] 該部分內(nèi)容設(shè)置打印機(jī)共享。

3.samba實(shí)踐一
要求共享一個(gè)目錄,任何人都可以訪問(wèn),即不用輸入密碼即可訪問(wèn),要求只讀;

[root@samba-server samba]# cp /etc/samba/smb.conf /etc/samba/smb.conf.ori
[root@samba-server samba]# egrep -v "^$|#|;" /etc/samba/smb.conf.ori >smb.conf

在配置文件/etc/samba/smb.conf中做如下修改(紅顏色字體為修改的內(nèi)容)
[root@samba-server samba]# cat /etc/samba/smb.conf
[global]
workgroup =WORKGROUP
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
security =?share
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
[share]

comment = share allpath = /tmp/sambabrowseable = yespublic = yeswritable = no

mkdir /tmp/samba
chmod 777 /tmp/samba
touch /tmp/samba/sharefile
echo "111111" > /tmp/samba/sharefile
testparm 測(cè)試配置文件
/etc/init.d/smb start
netstat -lntup|grep smb

[root@samba-server samba]# netstat -lntup|grep smb
tcp 0 0 0.0.0.0:139 0.0.0.0:?LISTEN 3338/smbd?
tcp 0 0 0.0.0.0:445 0.0.0.0:?LISTEN 3338/smbd?
tcp 0 0 :::139 :::?LISTEN 3338/smbd?
tcp 0 0 :::445 :::?LISTEN 3338/smbd

啟動(dòng):/etc/init.d/smb start?
檢查配置的smb.conf是否正確 testparm
測(cè)試:windows機(jī)器瀏覽器輸入 file://192.168.56.17/share
或者運(yùn)行欄輸入: \192.168.56.17 或 \192.168.56.17 \share

瀏覽器顯示:

root@samba-server samba]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[share]"
WARNING: The security=share option is deprecated 有警告,但是不影響測(cè)試
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
server string = Samba Server Version %v
security = SHARE
log file = /var/log/samba/log.%m
max log size = 50
client signing = required
idmap config * : backend = tdb
cups options = raw

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

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

[share]
comment = share all
path = /tmp/samba
guest ok = Yes

4.Samba實(shí)踐二
共享一個(gè)目錄,使用用戶名和密碼登錄后才可以訪問(wèn),要求可以讀寫;
[root@samba-server samba]# cat /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
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

#[share]
comment = share all
path = /tmp/samba
browseable = yes
public = yes
writable = no
[myshare]
comment = share for users
path = /samba
browseable = yes
writable = yes
public = no

[root@samba-server /]# mkdir /samba
[root@samba-server /]# chmod 777 /samba/
[root@samba-server /]# useradd test01
[root@samba-server /]# useradd test02

[root@samba-server /]# pdbedit -a test02
new password:
retype new password:
Unix username: test02
NT username:?
Account Flags: [U ]
User SID: S-1-5-21-3196454316-2411642794-2178690100-1001
Primary Group SID: S-1-5-21-3196454316-2411642794-2178690100-513
Full Name:?
Home Directory: \samba-server\test02
HomeDir Drive:?
Logon Script:?
Profile Path: \samba-server\test02\profile
Domain: SAMBA-SERVER
Account desc:?
Workstations:?
Munged dial:?
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Fri, 05 Aug 2016 17:33:23 CST
Password can change: Fri, 05 Aug 2016 17:33:23 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

[root@samba-server /]# pdbedit -a test01
new password:
retype new password:
Passwords do not match!
[root@samba-server /]# pdbedit -a test01
new password:
retype new password:
Unix username: test01
NT username:?
Account Flags: [U ]
User SID: S-1-5-21-3196454316-2411642794-2178690100-1000
Primary Group SID: S-1-5-21-3196454316-2411642794-2178690100-513
Full Name:?
Home Directory: \samba-server\test01
HomeDir Drive:?
Logon Script:?
Profile Path: \samba-server\test01\profile
Domain: SAMBA-SERVER
Account desc:?
Workstations:?
Munged dial:?
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Fri, 05 Aug 2016 17:33:07 CST
Password can change: Fri, 05 Aug 2016 17:33:07 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

5.Samba實(shí)踐三
samba服務(wù)端,先暫停用戶,賬號(hào)標(biāo)記為[DU],正常狀態(tài)為[U];客戶端訪問(wèn),提示賬號(hào)不可用;

[root@samba-server samba]# pdbedit -c [D] -u test01
Unix username: test01
NT username:?
Account Flags: [DU ]
User SID: S-1-5-21-3196454316-2411642794-2178690100-1000
Primary Group SID: S-1-5-21-3196454316-2411642794-2178690100-513
Full Name:?
Home Directory: \samba-server\test01
HomeDir Drive:?
Logon Script:?
Profile Path: \samba-server\test01\profile
Domain: SAMBA-SERVER
Account desc:?
Workstations:?
Munged dial:?
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Fri, 05 Aug 2016 17:55:14 CST
Password can change: Fri, 05 Aug 2016 17:55:14 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

[root@samba-server samba]# smbclient //192.168.56.17/myshare -Utest01
Enter test01's password:?
session setup failed: NT_STATUS_ACCOUNT_DISABLED

samba服務(wù)端恢復(fù)用戶,賬號(hào)標(biāo)記為[U];客戶端訪問(wèn),恢復(fù)正常;

[root@samba-server samba]# pdbedit -c [] -u test01
[root@samba-server samba]# smbclient //192.168.56.17/myshare -Utest01
Enter test01's password:?
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]
smb: \>

smb: \> ls
. D 0 Fri Aug 5 17:38:07 2016
.. DR 0 Fri Aug 5 17:31:37 2016
contest 10 Fri Aug 5 17:38:07 2016

41119 blocks of size 131072. 13988 blocks available

[root@samba-server samba]# pdbedit -c [D] -u test02
Unix username: test02
NT username:?
Account Flags: [DU ]
User SID: S-1-5-21-3196454316-2411642794-2178690100-1001
Primary Group SID: S-1-5-21-3196454316-2411642794-2178690100-513
Full Name:?
Home Directory: \samba-server\test02
HomeDir Drive:?
Logon Script:?
Profile Path: \samba-server\test02\profile
Domain: SAMBA-SERVER
Account desc:?
Workstations:?
Munged dial:?
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Fri, 05 Aug 2016 17:33:23 CST
Password can change: Fri, 05 Aug 2016 17:33:23 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

[root@samba-server samba]# smbclient //192.168.56.17/myshare -Utest02
Enter test02's password:?
session setup failed: NT_STATUS_ACCOUNT_DISABLED

[root@samba-server samba]# pdbedit -c [] -u test02|grep -i Account
Account Flags: [U ]
Account desc:

[root@samba-server samba]# smbclient //192.168.56.17/myshare -Utest02
Enter test02's password:?
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]
smb: \> ls
. D 0 Fri Aug 5 17:38:07 2016
.. DR 0 Fri Aug 5 17:31:37 2016
contest 10 Fri Aug 5 17:38:07 2016

41119 blocks of size 131072. 13988 blocks available

smb: \> q

[root@samba-server ~]# pdbedit -L
test01:504:
刪除用戶:
[root@samba-server ~]# pdbedit -x test01
[root@samba-server ~]# pdbedit -L
[root@samba-server samba]# pdbedit -x test02
[root@samba-server ~]#

[root@samba-server ~]# smbclient //192.168.56.17/myshare -Utest02
Enter test02's password:?
session setup failed: NT_STATUS_LOGON_FAILURE

6.Linux訪問(wèn)samba共享文件
參考文檔:
http://mofansheng.blog.51cto.com/8792265/1654871

[root@samba-client ~]# yum install -y samba-client

安裝客戶端軟件 yum install -y samba-client
命令格式:smbclient //IP/共享名 -U 用戶名
如:smbclient //127.0.0.1/share 如果是匿名訪問(wèn)可以省略掉-U

[root@samba-client ~]# mount -t cifs //192.168.56.17/myshare /mnt -o username=test01,password=123456
[root@samba-client ~]# smbclient //192.168.56.17/myshare -Utest01?
Enter test01's password: 123456
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]
smb: \> q

mount -t cifs //192.168.0.22/myshare /mnt 匿名訪問(wèn)不需要-o參數(shù);
如執(zhí)行命令提示參數(shù)有錯(cuò),還需要安裝cifs-utils包;

[root@samba-client ~]# smbclient //192.168.56.17/myshare -Utest01
Enter test01's password: 1234 輸錯(cuò)密碼報(bào)錯(cuò)?
session setup failed: NT_STATUS_LOGON_FAILURE

輸入正確密碼后進(jìn)入,put上傳文件,get下載文件;上傳的文件smb服務(wù)器中查看所屬主、組為user1;user1在共享文件夾可以新建目錄,刪除文件;help可以列出當(dāng)前命令行可以執(zhí)行的命令;

必須先在samba-client當(dāng)前目錄下創(chuàng)建文件,才能上傳對(duì)應(yīng)的文件到samba-server端的共享目錄下/share 下,而且通過(guò)test01 用戶登陸的上傳的文件到samba-server 服務(wù)端的share下,顯示該文件的用戶和用戶組為test01.

[root@samba-client ~]# echo 123 >1.sql
[root@samba-client ~]# ls -ls
total 8
4 -rw-r--r-- 1 root root 4 Aug 5 18:51 1.sql
4 -rw-r--r-- 1 root root 10 Aug 5 18:48 contest

[root@samba-client ~]# smbclient //192.168.56.17/myshare -Utest01
Enter test01's password:?
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]
smb: \> put 1.sql
putting file 1.sql as \1.sql (0.8 kb/s) (average 0.8 kb/s)

[root@samba-server samba]# ll
total 8
-rwxr--r-- 1 test01 test01 4 Aug 5 18:51 1.sql
-rw-r--r-- 1 root root 10 Aug 5 17:38 contest

[root@samba-client ~]# smbclient //192.168.56.17/myshare -Utest01
Enter test01's password:?
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]
smb: \>get contest
getting file \contest of size 10 as contest (1.2 KiloBytes/sec) (average 1.2 KiloBytes/sec)

[root@samba-client ~]# ls
contest
[root@samba-client ~]# cat contest?
Wujianwei

客戶端mount掛載samba共享文件到本地
mount -t cifs //192.168.56.17/myshare /mnt -o username=test01,password=123456

[root@samba-client ~]# mount
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda2 on /data type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
//192.168.56.17/myshare on /mnt type cifs (rw,username=test01,password=123456)

7實(shí)例共享文件訪問(wèn)權(quán)限的控制
http://304076020.blog.51cto.com/7503470/1367740

nginx+lwa
http://lee90.blog.51cto.com/10414478/1833724

編輯samba的配置文件:
comment:注釋信息;
path:當(dāng)前共享所映射的文件系統(tǒng)路徑;
browseable:是否可瀏覽,指是否可被用戶查看;
guest ok:是否允許來(lái)賓賬號(hào)訪問(wèn);
public:是否公開(kāi)所有用戶;
writable:是否可寫;
write list:擁有寫權(quán)限的用戶列表;

vim /etc/samba/smb.conf

comment = wordpress 名稱
path = /data/application/web 要導(dǎo)出的路徑
browseable = yes?
writable = yes
2.客戶端配置:
掛載:
mount -t cifs -o username=apachepassword=admin //172.16.35.1/wordpress /var/www/html

參考資料:
Samba服務(wù)共享的Linux和windows 參數(shù)介紹:
http://yuanbin.blog.51cto.com/363003/115761/
http://www.linuxidc.com/Linux/2015-05/117977.htm


?本文轉(zhuǎn)自 wjw555 51CTO博客,原文鏈接:http://blog.51cto.com/wujianwei/2057172


總結(jié)

以上是生活随笔為你收集整理的Samba 服务共享的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。