Linux進階-1.安裝samba服務

Samba是在Linux和UNIX系統上實現SMB協議的一個免費軟件,由服務器及客戶端程序構成。SMB(Server Messages Block,信息服務塊)是一種在局域網上共享文件和打印機的一種通信協議,它爲局域網內的不同計算機之間提供文件及打印機等資源的共享服務。

1.服務安裝

[root@linux etc]# yum install samba -y
已加載插件:langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel                                                     | 4.1 kB     00:00     
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 samba.x86_64.0.4.1.1-31.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

================================================================================
 Package         架構             版本                     源              大小
================================================================================
正在安裝:
 samba           x86_64           4.1.1-31.el7             rhel           527 k

事務概要
================================================================================
安裝  1 軟件包

總下載量:527 k
安裝大小:1.5 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安裝    : samba-4.1.1-31.el7.x86_64                                   1/1 
  驗證中      : samba-4.1.1-31.el7.x86_64                                   1/1 

已安裝:
  samba.x86_64 0:4.1.1-31.el7                                                   

完畢!

2.編輯配置文件

[root@linux etc]# cat /etc/samba/smb.conf 
# This is the main Samba configuration file. For detailed information about the
# options listed here, refer to the smb.conf(5) manual page. Samba has a huge
# number of configurable options, most of which are not shown in this example.
#
# The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step
# guides for installing, configuring, and using Samba:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
以下省略...

由於配置文件太多,將一些前面帶井號的註釋刪除

[root@linux etc]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@linux etc]# cat  /etc/samba/smb.conf.bak | grep -v '#' | grep -v ';' | grep -v '^$' > /etc/samba/smb.conf
[root@linux etc]# cat /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

刪除沒有用的參數,邊界用戶的訪問配置。

[root@linux etc]# vim /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
[shijie]
        comment = hello world
        path = /home/shijie
        public = no
        writable = yes

3.創建用戶

pdbedit命令用於管理SMB服務程序的賬戶信息數據庫,格式爲“pdbedit [選項] 賬戶”。

參數			作用
-a 用戶名	建立Samba用戶
-x 用戶名	刪除Samba用戶
-L			列出用戶列表
-Lv			列出用戶詳細信息的列表

創建samba的用戶和密碼,是客戶端訪問服務器的賬號和密碼。

[root@linux etc]# pdbedit -a -u shijie
new password:
retype new password:
Unix username:        shijie
NT username:          
Account Flags:        [U          ]
User SID:             S-1-5-21-2209934372-3311476088-2956246234-1000
Primary Group SID:    S-1-5-21-2209934372-3311476088-2956246234-513
Full Name:            shijie
Home Directory:       \\linux\shijie
HomeDir Drive:        
Logon Script:         
Profile Path:         \\linux\shijie\profile
Domain:               LINUX
Account desc:         
Workstations:         
Munged dial:          
Logon time:           0
Logoff time:          三, 06 2月 2036 23:06:39 CST
Kickoff time:         三, 06 2月 2036 23:06:39 CST
Password last set:    二, 19 5月 2020 00:40:53 CST
Password can change:  二, 19 5月 2020 00:40:53 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

4.重啓服務

[root@linux etc]# systemctl restart smb
[root@linux etc]# systemctl enable smb

5.清空防火牆策略

[root@linux etc]# iptables -F
[root@linux Desktop]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  確定  ]

6.關閉selinux

[root@linux etc]# setenforce 0
[root@linux Desktop]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

7.訪問共享

7.1Windows訪問samba服務器

在開始運行或者windows資源管理器中輸入:\\192.168.10.10
在這裏插入圖片描述
輸入在服務器中配置的用戶名密碼
在這裏插入圖片描述
輸入正確的用戶名密碼後就可以看到服務器共享的文件了
在這裏插入圖片描述
進入共享文件目錄中,新建一個文件夾
在這裏插入圖片描述
在服務端同步出現了新的文件夾
在這裏插入圖片描述

7.2Linux客戶端訪問samba服務器

在客戶端上安裝cifs服務

[root@localhost ~]# yum install cifs-utils -y
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package cifs-utils.x86_64 0:6.2-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch             Version             Repository      Size
================================================================================
Installing:
 cifs-utils           x86_64           6.2-6.el7           rhel            83 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 83 k
Installed size: 174 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : cifs-utils-6.2-6.el7.x86_64                                  1/1 
  Verifying  : cifs-utils-6.2-6.el7.x86_64                                  1/1 

Installed:
  cifs-utils.x86_64 0:6.2-6.el7                                                 

Complete!

創建一個認證文件,將服務器配置的用戶名、密碼和工作組編輯進去,並修改只有root用戶可以讀寫的權限。

[root@localhost ~]# vim password
username=shijie
password=shijie
domain=MYGROUP
[root@localhost ~]# chmod 600 password 
[root@localhost ~]# ls -l password
-rw-------. 1 root root   47 May 19 15:32 password

在桌面創建文件夾用於掛載服務器共享的文件目錄

[root@localhost Desktop]# mkdir shijie
[root@localhost Desktop]# ls
109  109.tar.gz  shijie

將掛載信息寫入fstab文件中,並掛載。

[root@localhost Desktop]# echo ‘//192.168.10.10/shijie /root/Desktop/shijie cifs credentials=/root/password 0 0’ >> /etc/fstab
[root@localhost Desktop]# mount -a

掛載後可以看到服務器共享的文件了,在文件中創建新文件可以發現服務器中的文件也會實時了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章