服务器 频道

Samba应用案例答案

  【IT168 服务器学院】首先要把smb.conf文件还原

  1。加入sales组

  #groupadd sales

  #groupadd tech

  2.给组分别加入用户

  #useradd -a sales -s /bin/false tom

  #useradd -a sales -s /bin/false jack

  #useradd -a tech  -s /bin/false blue

  #useradd -a tech  -s /bin/false red

  其中的-s /bin/false选项是为了防止用户使用shell

  3.必须在smbpasswd中也加入用户帐号

  #smbpasswd -a tom

  #smbpasswd -a jack

  这两个用户没有系统密码只有smb密码,

  当用户比较多时,我们需要用脚本来添加用户:

  #for user in red blue

  >do

  > useradd -g tech -s /bin/false $user

  >smbpasswd -a $user

  >done

  New SMB password:           (这里是red的密码)

  Retype new SMB password:

  Added user red.

  New SMB password:           (这里是blue的密码)

  Retype new SMB password:

  Added user blue.

  #more /etc/samba/smbpasswd

  这里可以看到我们刚才添加的帐号,接着是添加ceo和finance帐号

  #useradd ceo

  #useradd finance

  #smbpasswd -a ceo

  #smbpasswd -a finance

  到此为止帐号已经建立好了

  4.#mkdir /home/sales /home/tech

  接着要修改这两个目录的权限

  #chgrp sales /home/sales

  #chgrp tech  /home/tech

  #chmod 770   /home/sales

  #chmod 770   /home/tech

  为了保证目录权限永远共享下去,再加上一下2句

  #chmod g+s /home/sales

  #chmod g+s /home/tech

  5.下面就是修改smb.conf文件,添加

  [sales]  和  [tech]两个文件夹

  [sales]

      path=/home/sales

      comment=sales

      public=no

      valid users=@sales

      write list=@sales

      create mask=0770

      directory mask=0770

  [tech]

      path=/home/tech

      comment=tech

      public=no

      valid users=@tech

      write list=@tech

      create mask=0770

      directory mask=0770

  6.随后先自己测试一下

  #smbclient -L 10.24.2.1 -U red%red

  可以看到:

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  added interface ip=10.24.2.1 bcast=10.24.7.255 nmask=255.255.248.0

  Domain=[WORKGROUP] OS=[Unix] Server=[Samba 2.2.7a]

          Sharename      Type      Comment

          ---------      ----      -------

          sales          Disk      sales

          tech           Disk      tech

          IPC$           IPC       IPC Service (Samba Server)

          ADMIN$         Disk      IPC Service (Samba Server)

          red            Disk      Home Directories

          Server               Comment

          ---------            -------

          SERVER               Samba Server

          Workgroup            Master

          ---------            -------

          WORKGROUP

  说明我们的配置是正确的。

  我们再试验一下用ceo帐号访问别人的目录例如sales

  [root@server root]# smbmount //10.24.2.1/sales /mnt -o username=ceo%ceo

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  1867: tree connect failed: ERRSRV - ERRbadpw (Bad password - name/password pair in a Tree Connect or Session Setup are invalid.)

  SMB connection failed

我们可以看到不可以访问,我们再用ceo访问自己的home/ceo目录看看如何

  [root@server root]# smbmount //10.24.2.1/ceo /mnt -o username=ceo%ceo

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: w

  params.c:Parameter() - Ignoring badly formed line in configuration file: p

  然后我们到/mnt目录下看看如何:

  [root@server mnt]# ls -a

  .  ..  .bash_logout  .bash_profile  .bashrc  .emacs

  我们可以看到/mnt目录下已经挂载内容了,说明我们配置是正确的。

  我们也可以用tom访问工作组sales目录

  最后我们就可以在windows的网上邻居里用特定的帐号访问特定的目录了。

  我们所做的大量工作其实是在建立帐号、目录以及给目录分配权限上,真正用到samba配置的只是很少的一部分而已。

0
相关文章