samba服务器的搭建

一.samba共享服务器

著名的桑巴舞计算机中有一个软件也叫Samba samba是一个能让你的Unix计算机和其它MS Windows计算机相互共享资源的软件。samba提供有关资源共享的三个功能,包括:smbd,执行它可以使Unix能够共享资源给其它的计算机;而smbclient就是让Unix去存取其它计算机的资源;最后一个smbmount,则是类似MS Windwos下“网络磁盘驱动器”的功能,可以让你把其它计算机的资源挂在自己的档案系统下。它们功能虽然简单,但没有samba,Unix和Windows的资源就很难

二.samba服务器搭建

第一步:首先安装必要的软件包

[root@111 ~]# mount  /dev/cdrom  /mnt/cdrom/

[root@111 ~]# cd  /mnt/cdrom/Server/

[root@111 Server]# rpm -qa |grep  samba
samba-client-3.0.33-3.14.el5   //默认情况下已经安装的客户端
samba-common-3.0.33-3.14.el5   //生成配置文件的软件包

[root@111 Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm
error: Failed dependencies:
    perl(Convert::ASN1) is needed by samba-3.0.33-3.14.el5.i386

[root@111 Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm
Preparing...                #################################### [100%]
   1:perl-Convert-ASN1      ################################# [100%]
[root@111 Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm
Preparing...                ########################################### [100%]
   1:samba                  ########################################### [100%]

查看samba服务相关的目录及文件

[root@111 Server]# rpm -ql samba

/etc/pam.d/samba

/etc/rc.d/init.d/smb

/etc/samba/smbusers
/etc/sysconfig/samba
/usr/bin/mksmbpasswd.sh
/usr/bin/smbcontrol
/usr/bin/smbstatus
/usr/bin/tdbbackup
/usr/bin/tdbdump
/usr/bin/tdbtool

/usr/sbin/nmbd
/usr/sbin/smbd

第二步:修改配置文件

[root@111 Server]# vim /etc/samba/smb.conf

80         interfaces = lo eth0  192.168.10.244/24

81         bind interfaces only = yes

82         hosts allow = 127. 192.168.10.

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

95         max log size = 50

105         security = user
106         passdb backend = tdbsam

添加公共共享

267 [public]
268         comment =  this is a public dir
269         path = /abc
270         browseable = yes
271         guest ok = yes
272         writable = no

添加私有目录
273 [user1]
274         comment = this is user1 share
275         path = /home/user1
276         browseable = yes
277         guest ok = no
278         writable = yes
279         valid users = user1
280         valid users = MYDOMAIN\%S

添加私有目录

281 [user2]
282         comment = this is user2 share
283         path = /home/user2
284         browseable = yes
285         guest ok = no
286         writable = yes
287         valid users = user2
288         valid users = MYDOMAIN\%S

重启samba服务

[root@111 Server]# service smb restart
Shutting down SMB services:                                [FAILED]
Shutting down NMB services:                                [FAILED]
Starting SMB services:                                     [  OK  ]
Starting NMB services:                                     [  OK  ]

第三步:向账号库中添加账号

[root@111 Server]# cat /etc/passwd  |grep "^user"
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash

[root@111 Server]# smbpasswd  -a user1
New SMB password:123
Retype new SMB password:123
Added user user1.
[root@111 Server]# smbpasswd  -a user2
New SMB password:123
Retype new SMB password:123
Added user user2.

创建公共公共的分享目录

mkdir /abc

touch  /abc/f1.public

touch /home/user1/f1.user1

touch /home/user2/f1.user2

[root@111 Server]# chown user1.user1 /home/user1/f1.user1
[root@111 Server]# chown user2.user2 /home/user2/f1.user2

第四步:测试共享

在windows客户端上适应“运行”输入“\\192.168.10.244”

使用user1 账号登陆:

image

在public中可以下载及查看权限但是没有写入

重命名失败

image

新建文件失败

image

上传文件失败

image

在自己的家目录中

写入,上传及修改的权限

当访问user2的分享时需要账户和密码

image 

第四步:使用linux客户端访问共享

[root@111 Server]# smbclient -L //192.168.10.244    //使用匿名查看网络共享
Password: ENTER
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]

    Sharename       Type      Comment
    ---------       ----      -------
    public          Disk      this is a public dir
    user1           Disk      this is user1 share
    user2           Disk      this is user2 share
    IPC$            IPC       IPC Service (Samba Server Version 3.0.33-3.14.el5)
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]

    Server               Comment
    ---------            -------
    111                  Samba Server Version 3.0.33-3.14.el5

    Workgroup            Master
    ---------            -------
    MSHOME               DONGHAODONG
    MYGROUP              111

[root@111 Server]# smbclient  //192.168.10.244/user1  -U  user1
Password:
Domain=[111] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
smb: \> dir
  .                                   D        0  Wed Aug  8 12:50:03 2012
  ..                                  D        0  Mon Aug  6 20:01:18 2012
  mail                                D        0  Mon Aug  6 20:40:27 2012
  .bash_profile                       H      176  Sat Aug  4 13:09:05 2012
  .bashrc                             H      124  Sat Aug  4 13:09:05 2012
  .mozilla                           DH        0  Sat Aug  4 13:09:05 2012
  .bash_history                       H       13  Mon Aug  6 13:27:20 2012
  .kde                               DH        0  Sat Aug  4 13:09:05 2012
  f1.user1                            A        0  Wed Aug  8 12:35:58 2012
  .bash_logout                        H       33  Sat Aug  4 13:09:05 2012
  .emacs                              H      515  Sat Aug  4 13:09:05 2012
  .zshrc                              H      658  Sat Aug  4 13:09:05 2012
  mbox                                       544  Mon Aug  6 13:27:11 2012

        38752 blocks of size 262144. 23965 blocks available
smb: \> exit

第五步:在linux中远程挂载

手动挂载

[root@111 Server]# mkdir /mnt/smb

[root@111 Server]# mount -t cifs //192.168.10.244/user1 /mnt/smb -o username=user1%123

[root@111 Server]# mount

//192.168.10.244/user1 on /mnt/smb type cifs (rw,mand)  //成功挂载

自动挂载

[root@111 Server]# umount /mnt/smb

编辑fstab文件

[root@111 Server]# vim /etc/fstab

8 //192.168.10.244/user1  /mnt/smb                cifs    defaults,username=user1%123   0 0

[root@111 Server]# mount

//192.168.10.244/user1 on /mnt/smb type cifs (rw,mand)

安全的自动挂载

8 //192.168.10.244/user1  /mnt/smb                cifs    defaults,credentials=/etc/samba/passwd   0 0

[root@111 Server]# vim  /etc/samba/passwd

username=user1
password=123

[root@111 Server]# umount /mnt/smb

[root@111 Server]# mount

//192.168.10.244/user1 on /mnt/smb type cifs (rw,mand)  //已经成功挂载

             嗯,韩宇说的对!!!

你可能感兴趣的:(windows,linux,samba,共享资源)