Linux下使用samba伺服器實現

2021-07-26 13:50:39 字數 4546 閱讀 4192

很多情況下我們在虛擬機上安裝的linux系統通常都要用到與windows實現檔案的共享這一功能;

以前我基本都是在虛擬機器(red hat enterprise linux 5)下安裝vmtools來實現這一功能,這是我第一次使用samba伺服器來實現這一功能,下面的操作已經在本人的虛擬機器上實踐通過(red hat enterprise linux 5)

2.在本地建立乙個samba共享的目錄資料夾(如/home/sharefolder)

[root@localhost home]# pwd

/home

[root@localhost home]# ls

sunrier

[root@localhost home]# mkdir sharefolder

[root@localhost home]# pwd

/home

[root@localhost home]# ls

sharefolder  sunrier

[root@localhost home]# ll

總計 20

drwxr-xr-x 2 root       root     4096 08-30 10:04 sharefolder

drwx------ 3 sunrier    sunrier  4096 08-29 11:25 sunrier

[root@localhost home]# chmod -r 777 sharefolder

[root@localhost home]# ll

總計 20

drwxrwxrwx 2 root       root     4096 08-30 10:04 sharefolder

drwx------ 3 sunrier    sunrier  4096 08-29 11:25 sunrier

[root@localhost home]#

3.關閉samba伺服器

檢視samba伺服器狀態

[root@localhost ~]# service smb status

smbd 已停

nmbd 已停

[root@localhost ~]#

由上面的檢視結果可以看出此時samba服務沒有開啟,處於關閉狀態;

如果沒有關閉,使用service smb stop 命令關閉samba服務

4.修改/etc/samba/smb.cnf配置檔案

(1)把/etc/samba/smb.cnf配置檔案裡的 security = user 修改為 security = share ;

share即表示安全性為共享模式

(2)在/etc/samba/smb.cnf配置檔案結尾加上如下配置內容

[sharefolder]

comment = share

path = /home/sharefolder

public = yes

browseable = yes

writable = yes

;printable = no

配置說明:

[sharefolder]       #共享目錄的名字

comment = share      #共享目錄的說明,相當於注釋

path = /home/sharefolder #共享目錄的路徑

public = yes       #指定目錄是否可以guest訪問

browseable = yes     #指定目錄是否可以容許瀏覽

writable = yes      #指定目錄是否可以寫(yes為可寫,no為只可讀)

;printable = no      #指定目錄是否可以列印(yes為可列印,no為不可以列印)

#配置的內容前面加;相當於注釋,這句不起作用

5.開啟samba伺服器

[root@localhost ~]# service smb start

啟動 smb 服務:                                            [確定]

啟動 nmb 服務:                                            [確定]

[root@localhost ~]# pstree | grep mbd

|-nmbd

|-smbd---smbd

[root@localhost ~]#

注:如果想開機就啟動samba服務,那麼執行下面命令

先設定開機啟動samba服務,然後重啟

[root@localhost ~]# chkconfig smb on

[root@localhost ~]# reboot

6.檢視虛擬機器ip位址

[root@localhost ~]# ifconfig

eth0      link encap:ethernet  hwaddr 00:0c:29:c8:c4:67  

inet addr:192.168.168.130  bcast:192.168.168.255  mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fec8:c467/64 scope:link

up broadcast running multicast  mtu:1500  metric:1

rx packets:446 errors:0 dropped:0 overruns:0 frame:0

tx packets:271 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000 

rx bytes:54895 (53.6 kib)  tx bytes:39131 (38.2 kib)

interrupt:67 base address:0x2024

lo        link encap:local loopback  

inet addr:127.0.0.1  mask:255.0.0.0

inet6 addr: ::1/128 scope:host

up loopback running  mtu:16436  metric:1

rx packets:1924 errors:0 dropped:0 overruns:0 frame:0

tx packets:1924 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0 

rx bytes:2909336 (2.7 mib)  tx bytes:2909336 (2.7 mib)

[root@localhost ~]#

7.在windows的執行裡面輸入: \\192.168.168.130 或者\\192.168.168.130\sharefolder,即實現共享

補充說明:

1.網上有的教程可能帶有關閉防火牆,我在本次實踐中沒有關閉防火牆

關閉redhat防火牆

[root@localhost ~]# iptables -f

[root@localhost ~]#

或者[root@localhost ~]# service iptables stop

2.上面操作在安裝完軟體包後,也可以通過圖形介面設定

步驟:(1)先關閉samba服務

(2)選擇"系統"->"管理"->"伺服器設定"->"samba"

(3)選擇"新增共享"

在"基本"視窗:

設定共享目錄

設定共享名

設定描述

設定讀寫許可權

設定是否顯示

在"訪問"視窗:

設定使用者訪問許可權

(4)選擇"首選專案"->"伺服器設定"

在"基本"視窗:

可以不設定,預設設定

在"安全性"視窗:

設定驗證模式為"共享"

其他為預設設定

(5)啟動samba服務

(6)檢視虛擬機器ip位址

(7)在windows的執行裡面輸入: \\虛擬機器ip位址 或者\\虛擬機器ip位址\共享名,即實現共享

注:本次的實踐操作所有使用者都有訪問操作的許可權

redhat安裝vmtools步驟:

1.切換到root許可權

2.掛載虛擬光碟

mount /dev/cdrom /mnt/cdrom

如果/mnt下沒有cdrom目錄,需要mkdir cdrom

3.cd /tmp

4.刪除以前的目錄vmware-tools-distrib 

一般放在/tmp/vmware-tools-distrib

5.tar zxpf /mnt/cdrom/vmwaretools-.tar.gz

umount /dev/cdrom

6.cd vmware-tools-distrib

./vmware-install.pl

7./etc/init.d/network stop

rmmod vmxnet

modprobe vmxnet

/etc/init.d/network start

注:參考vmtools安裝說明步驟即可。

linux 下samba使用簡介

今天裝了一台真正的linux主機 red hat 呵呵。安裝好了ftp,ssh等服務,但是好像還需要個window能和linux共享資料夾的軟體samba,還好,一開始在安裝linux的時候,就按照了smaba,如果沒有,我們可以在iso中提取rpm包來安裝。主要參考文獻為 1.確認smaba是否安...

Linux下安裝Samba伺服器

1.終端輸入 sudo apt get install samba samba common 2.新建共享目錄 sudo mkdir home share 3.設定許可權 sudo chmod 777 home share 4.修改配置檔案 sudo vim etc samba smb.conf 在...

Linux下搭建Samba伺服器

samba是在linux和unix系統上實現smb協議的乙個免費軟體,由伺服器及客戶端程式構成,smb server messages block,資訊服務塊 是一種在區域網上共享檔案和印表機的一種通訊協議,它為區域網內的不同計算機之間提供檔案及印表機等資源的共享服務。smb協議是客戶機 伺服器型協...