天天看點

samba (smb)

1、介紹;

smb協定(samba程式),是一組用來在區域網路中共享檔案、列印機裝置的協定。

在smb協定出現之前,已存在ftp及nfs。

ftp可以實作網絡檔案的浏覽,下載下傳及上傳,但卻無法很友善的對網絡檔案進行檢視、修改。

nfs(networkfile system)解決了ftp的問題,可以友善的檢視及修改網絡檔案。但是隻能在windows之間使用。

是以tridgwell開發出了smb協定(server message block),支援windows與linux系統檔案共享。當然也支援windows之間,linux之間的檔案共享。

之是以叫samba這個名字是由于smbserver這個名字注冊被拒絕了。

2、應用情況舉例:

我們在windows上安裝了linux虛拟機ubuntu,并于ubuntu中下載下傳了code。

此時很多時候我們并不希望在ubuntu中去浏覽、修改code,

因為對我們來說在windows下使用source insight浏覽修改大工程code會更舒服些。

在這個情況下,我們就可以使用samba将code共享給windows,這樣檢視修改代碼可以在windows中進行,而編譯可以在securecrt中進行,這樣ubuntu可以一直隐藏在背景(作為一台虛拟伺服器存在)。

3、使用samba共享檔案給windows舉例:

samba配置檔案路徑 /etc/samba/smb.conf

samba服務路徑/etc/init.d/smbd

3.1、确認我們的系統是否安裝并啟用了samba服務。

3.1.1、服務已開啟

jetxu@ubuntu:/etc/init.d$ ps -e|grep smb

   844 ?        00:00:00 smbd

   916 ?        00:00:00 smbd

   989 ?        00:00:00 smbd

  1908 ?        00:00:00 smbd

  2653 ?        00:00:00 smbd

jetxu@ubuntu:/etc/init.d$ ps au -e|grep smb

root        844  0.0  0.7 316720 15780 ?        ss   07:54   0:00 smbd -f

root        916  0.0  0.2 308760  5232 ?        s    07:54   0:00 smbd -f

root        989  0.0  0.3 316728  6688 ?        s    07:54   0:00 smbd -f

root       1908  0.0  0.7 324068 14668 ?        s    08:28   0:00 smbd -f

root       2653  0.0  0.7 324284 15432 ?        s    09:24   0:00 smbd -f

jetxu      2990  0.0  0.1  15948  2200 pts/0    s+   10:08   0:00 grep --color=auto smb

3.1.2、samba服務并沒有開啟

jetxu@ubuntu:/etc/init.d$ smbd start

3.1.3、samba并未安裝

jetxu@ubuntu:/etc/init.d$ sudo apt-get install samba

reading package lists... done

building dependency tree       

reading state information... done

samba is already the newest version.

the following packages were automatically installed and are no longer required:

  libntdb1 python-ntdb

use 'apt-get autoremove' to remove them.

0 upgraded, 0 newly installed, 0 to remove and 25 not upgraded.

3.2、配置smb.conf

3.2.1、我們大緻看看smb.conf内容

jetxu@ubuntu:/etc/samba$ cat smb.conf|grep -v "#" |grep -v ";" |grep -v "^$"> 1.txt

jetxu@ubuntu:/etc/samba$ cat 1.txt

[global]

   workgroup = workgroup

        server string = %h server (samba, ubuntu)

   dns proxy = no

   log file = /var/log/samba/log.%m

   max log size = 1000

   syslog = 0

   panic action = /usr/share/samba/panic-action %d

   server role = standalone server

   passdb backend = tdbsam

   obey pam restrictions = yes

   unix password sync = yes

   passwd program = /usr/bin/passwd %u

   passwd chat = *enter\snew\s*\spassword:* %n\n *retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

   pam password change = yes

   map to guest = bad user

   usershare allow guests = yes

[printers]  ##### 列印機的共享

   comment = all printers

   browseable = no

   path = /var/spool/samba

   printable = yes

   guest ok = no

   read only = yes

   create mask = 0700

[print$]

   comment = printer drivers

   path = /var/lib/samba/printers

   browseable = yes

#####   此處為我共享的檔案 ####

[msm9607]  #### 在網絡中的共享名

comment = say something about how to use this

read only = no

writeable=yes

locking = no

path = /home/jetxu/works   #### 共享路徑

public = no #### 此處使用yes的話,那麼所有人可以檢視該共享路徑(等同于 guest ok = yes)

samba (smb)

3.2.2、共享配置

3.2.3、賬戶配置

如果上面我們使用guest ok = yes選項,那麼不需要配置賬戶。

如果我們使用public = no 那麼如下,我們需要配置登入賬戶。

samba (smb)

比如我們配置賬戶jet

jetxu@ubuntu:~$ sudo useradd jet

[sudo] password for jetxu: 

jetxu@ubuntu:~$ sudo pdbedit -a jet

new password:

retype new password:

unix username:        jet

nt username:          

account flags:        [u          ]

user sid:             s-1-5-21-3603447644-3270005263-50691286-1003

primary group sid:    s-1-5-21-3603447644-3270005263-50691286-513

full name:            

home directory:       \\ubuntu\jet

homedir drive:        

logon script:         

profile path:         \\ubuntu\jet\profile

domain:               ubuntu

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:    wed, 21 sep 2016 11:06:22 cst

password can change:  wed, 21 sep 2016 11:06:22 cst

password must change: never

last bad password   : 0

bad password count  : 0

logon hours         : ffffffffffffffffffffffffffffffffffffffffff

3.2.4删除賬戶:

pdbedit -x jet

userdel jet

3.2.5windows無法通路我們虛拟機的位址

如果出現windows無法通路我們虛拟機的位址,那麼确認兩個事情

a、确定本機和目标機處于一個區域網路内,兩者有互通的基礎

b、确認目标機的防火牆是否屏蔽通路

對我們:

iptables -f   

service iptables save

繼續閱讀