生活随笔
收集整理的這篇文章主要介紹了
linux——samba共享以及基础用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Samba
Samba是在Linux和UNIX系統上實現SMB協議的一個免費軟件,有服務端和客戶端程序構成。隨著Linux的普及,如何共享Linux下的文件成為用戶關心的問題。其實,幾乎所有的Linux發行套件都提供了一個很好的工具Samba——通過它可以輕松實現文件共享
一、SMB文件共享
通用lnternet文件系統(CIFS)也稱為服務器信息塊(SMB),是適用于MicrosoftWindows服務器和客戶端的標準文件和打印機共享系統。
Samba服務可用于將Linux文件系統作為CIFS/SMB網絡文件共享進行共享,并將Linux打印機作為CIFS/SMB打印機共享進行共享。
[root@server ~]# ——服務端
[root@client ~]# ——客戶端
1、安裝以及啟動服務
[root
@server ~]
[root
@server ~]
[root
@server ~]
[root
@server ~]
[root
@server ~]
samba —— 服務器應用程序
samba-client —— 客戶端應用程序
samba-common —— Samba的支持文件
測試
客戶端進行測試,匿名登陸
因為在服務端未設置,所以不用輸入密碼,直接回車,登陸成功
[ ] - -
[ ] - ...
[] [] [ ..] --------- ---- ------- ..
[] [] [ ..] --------- ------- --------- -------
[ ]
2、添加smb用戶
smb用戶必須是本地用戶!!!
添加用戶student、tutu
[root@
server ~]
# smbpasswd -a student
New SMB password:
Retype
new SMB password:
Added user student.
[root@
server ~]
# useradd tutu
[root@
server ~]
# smbpasswd -a tutu
New SMB password:
Retype
new SMB password:
Added user tutu.
[root@
server ~]
# pdbedit -L
student:
1000:Student User
tutu:
1001:
[root@
server ~]
#
smbpasswd 常用參數-
a username: 添加用戶為samba用戶
-
d username:禁用samba用戶username
-
e username: 啟用samba用戶username
-
x username: 刪除samba用戶username
可以用 smbpasswd 添加 smb 用戶
還可以用 pdbedit 添加 smb 用戶
pdbedit 常用參數–
a username:新建
Samba賬戶。–
x username:刪除
Samba賬戶。–
L:列出
Samba用戶列表,讀取
passdb.tdb數據庫文件。–
Lv:列出
Samba用戶列表的詳細信息。–
c “
[D]” –
u username:暫停該
Samba用戶的賬號。–
c “
[]” –
u username:恢復該
Samba用戶的賬號。
測試
smbclient(選項)(參數)-
L:顯示服務器端所分享出來的所有資源
-
U<用戶名稱>:指定用戶名稱
- samba_enable_home_dirs
布爾值允許本地Linux主目錄作為CIFS文件共享導出至其他系統
測試
3、文件的上傳
只能上傳當前所在目錄下的文件
上傳的文件在服務端的 student 用戶的家目錄
- 上傳 /etc/passwd 成功,上傳 /bin/ls 失敗
- 轉到目錄 /bin ,上傳 /bin/ls 成功
注意:這種登陸方式登陸,不能執行新建文件、目錄等!!!
看看上傳的文件(服務端)
4、掛載CIFS共享(客戶端)
[root
@client ~]
[root
@client ~]
mount /
/172.25.254.227/student /mnt -o username=student,password=
123
[root
@client ~]
[root
@client ~]
5、域名的更改
[root
@server ~]
89 workgroup = MYGROUP --
-> workgroup = WESTOS
[root
@server ~]
6、smb服務的黒白名單
- 白名單
只允許 172.25.254.127 主機登陸
[root
@server ~]
[root
@server ~]hosts allow =
172.25.
254.127
[root
@server ~]
測試
[root
@server student]
[root
@server ~]hosts deny =
172.25.
254.127
[root
@server student]
測試
172.25.254.127
- 172.25.254.50
7、共享目錄的基本設定
[root
@server ~]
[root
@server ~]
[root
@server ~]
/westos(/.*)? all files
system_u:
object_r:
samba_share_t:s0
[root
@server ~]
restorecon reset /westos context
unconfined_u:
object_r:
default_t:s0->
system_u:
object_r:
samba_share_t:s0
[root
@server ~]
[root
@server ~][DIR] comment = westos dir path = /westos
[root
@server ~]hosts allow =
172.25.254.127/
24
[root
@server ~]
[root
@server ~]
file
[root
@server ~]
測試
[root@
server ~]
# vim /etc/samba/smb.conf ##添加后三行內容
[root@
server ~]
# cat /etc/samba/smb.conf | tail -n 3[mnt]
##共享名稱comment = /mnt dir
##對共享目錄的描述path = /mnt
##共享目錄的絕對路徑
[root@
server ~]
# systemctl restart smb
測試
測試
布爾值對于系統共享目錄的影響
[root
@server ~]
[root
@server ~]
file1
[root
@server ~]
Enforcing
[root
@server ~]
[root
@server ~]
[root
@server ~]
8、配置文件的參數
- browseable = no | yes ——更改此參數,不用重啟服務
no ——將該共享目錄設置為隱藏
yes——將該共享目錄設置為顯示
[root
@server ~]
[root
@server ~]browseable =
no
[root
@server ~]
測試
[root
@server ~]
[root
@server ~]browseable =
yes
[root
@server ~]
測試
[root
@server ~]
[root
@server ~]writable =
yes
[root
@server ~]
測試
寫操作失敗,是因為目錄/westos本身不可寫
[root
@server ~]
drwxr-xr-x.
2 root root
17 Jun 4 06:27 /westos/
[root
@server ~]
[root
@server ~]
drwxrwxrwx.
2 root root
17 Jun 4 06:27 /westos/
[root
@server ~]
測試
當/westos本身可寫后,寫操作執行成功
[root
@server ~]
[root
@server ~]
write list = student
[root
@server ~]
測試
[root
@server ~]
[root
@server ~]
write list =
@student
[root
@server ~]
[root
@server ~]
uid=
1001(tutu) gid=
1001(tutu) groups=
1001(tutu)
測試
[root
@server ~]
[root
@server ~]
uid=
1001(tutu) gid=
1001(tutu) groups=
1001(tutu),
1000(student)
[root
@server ~]
測試
[root
@server ~]
uid=
1001(tutu) gid=
1001(tutu) groups=
1001(tutu),
1000(student)
[root
@server ~]
drwxrwxrwx.
2 root root
30 Jun 4 08
:18 /westos/
[root
@server ~]
total
0
-rw-r--r--.
1 student student
0 Jun 4 08
:03 file1
-rw-r--r--.
1 tutu tutu
0 Jun 4 08
:18 file2
[root
@server ~]
[root
@server ~]writable = yes
admin users = tutu
[root
@server ~]
測試
9、多用戶掛載
不同用戶創建的文件、目錄等,所有的用戶都可以看
這是不合理的,下面的操作就是消除這種不合理
即設置多用戶掛載,掛載是需要 smb 認證
[root
@client ~]
[root
@client ~]
[root
@client ~]
username=student
password=
123
[root
@client ~]
[root
@client ~]
file1 file2 file3
[root
@client ~]
[root
@client ~]
[test
@client ~]
$ ls /mnt
ls: cannot access /
mnt: Permission denied
[test
@client ~]
$ cifscreds add -u tutu
172.25.
254.227
Password:
[test
@client ~]
$ ls /mnt
ls: cannot access /
mnt: Permission denied
[test
@client ~]
$ cifscreds add -u tutu
172.25.
254.227
You already have stashed credentials
for 172.25.
254.227 (
172.25.
254.227)
If you want to update them
use:cifscreds update
[test
@client ~]
$ cifscreds clearall
[test
@client ~]
$ cifscreds add -u tutu
172.25.
254.227
Password:
[test
@client ~]
$ ls /mnt
file1 file2 file3
[test
@client ~]
$ touch /mnt/file4
[test
@client ~]
$ ll /mnt/
total
0
-rw-r--r--
1 student student
0 Jun 4 08
:03 file1
-rw-r--r--
1 admin admin
0 Jun 4 08
:18 file2
-rw-r--r--
1 root admin
0 Jun 4 08
:30 file3
-rw-r--r--
1 root admin
0 Jun 4 08
:57 file4
[test
@client ~]
$ logout
[root
@client ~]
10、匿名用戶對于共享目錄的登陸與訪問
測試
[root
@server ~]
[root
@server ~]
map to guest = bad user
[root
@server ~]guest ok = yes
[root
@server ~]
測試
[root
@client ~]
Password for guest@/
/172.25.254.227/DIR:
這兩條命令在效果上等價
[root
@client ~]
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的linux——samba共享以及基础用法的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。