Sambaの最近のブログ記事

前提
ここでは以下のような環境を想定しています。
 ホスト : aries.tatsunet.net(192.168.0.141)
 OS : CentOS 4.2(Kernel 2.6.9-22.EL)

・各SambaユーザーのホームディレクトリとSambaユーザー全員で共有するディレクトリを公開します。
・Sambaユーザーはシェルではログインできないようにします。
・Windowsクライアントのエクスプローラー上で削除されたファイルは物理削除せずに、ごみ箱に移動する。
・ごみ箱に溜まったファイルはスクリプトで定期的に削除する。
・公開されたディレクトリ内にサブディレクトリ、ファイルが作成された場合は、以下のパーミッションで作成する。

 ホームディレクトリ共有ディレクトリ
サブディレクト755(drwxr-xr-x)2770(drwxrws---)
ファイル744(-rwxr--r--)770(-rwxrxw---)

Samba のインストール
yum でSamba をインストールします。


[root@aries ~]# yum install samba
   ・
   ・
   ・
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
samba i386 3.0.10-1.4E.6 base 13 M
Installing for dependencies:
samba-common i386 3.0.10-1.4E.6 base 5.0 M

Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 18 M
Is this ok [y/N]:
y
[root@aries ~]# yum list installed | grep samba
samba.i386 3.0.10-1.4E.6 installed
samba-common.i386 3.0.10-1.4E.6 installed

グループとユーザーの作成
グループとユーザーを作成します。
ここではグループ「smbusers」に属しているユーザーをSamba の利用者とします。
ここでは「tatsusmb1」「tatsusmb2」という二人のユーザーを作成します。


[root@aries ~]# groupadd smbusers
[root@aries ~]# useradd -s /sbin/nologin tatsusmb1
[root@aries ~]# useradd -s /sbin/nologin tatsusmb2
[root@aries ~]# passwd tatsusmb1
Changing password for user tatsusmb1.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@aries ~]# passwd tatsusmb2
Changing password for user tatsusmb2.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@aries ~]# usermod -G smbusers tatsusmb1
[root@aries ~]# usermod -G smbusers tatsusmb2

Sambaユーザーとして登録します。


[root@aries ~]# pdbedit -a tatsusmb1
new password:
retype new password:
startsmbfilepwent_internal: file /etc/samba/smbpasswd did not exist. File successfully created.
Unix username: tatsusmb1
NT username:
Account Flags: [U ]
User SID: S-1-5-21-2388817176-918761689-275094918-2000
Primary Group SID: S-1-5-21-2388817176-918761689-275094918-2003
Full Name:
Home Directory: \\aries\tatsusmb1
HomeDir Drive:
Logon Script:
Profile Path: \\aries\tatsusmb1\profile
Domain: ARIES
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: 土, 14 12月 1901 05:45:51 GMT
Kickoff time: 土, 14 12月 1901 05:45:51 GMT
Password last set: 月, 03 4月 2006 15:34:38 GMT
Password can change: 月, 03 4月 2006 15:34:38 GMT
Password must change: 土, 14 12月 1901 05:45:51 GMT
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@aries ~]# pdbedit -a tatsusmb2
   ・
   ・
   ・

共有ディレクトリの作成
共有ディレクトリと共有ディレクトリ配下のごみ箱(.recycle)を作成します。
ここでは/var/lib/samba/shareを共有ディレクトリとします。
※各ユーザーのホームディレクトリ配下のごみ箱は初めてファイルを削除したときに自動的に作成されます。


[root@aries ~]# mkdir -p /var/lib/samba/share
[root@aries ~]# chown root:smbusers /var/lib/samba/share
[root@aries ~]# chmod 2770 /var/lib/samba/share
[root@aries ~]# mkdir /var/lib/samba/share/.recycle
[root@aries ~]# chown root:smbusers /var/lib/samba/share/.recycle
[root@aries ~]# chmod 2770 /var/lib/samba/share/.recycle

smb.conf ファイルの編集
smb.conf ファイルを編集します。


[root@aries ~]# vi /etc/samba/smb.conf

/etc/samba/smb.conf


# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors.
#
#======================= Global Settings =====================================
[global]

dos charset = CP932
unix charset = UTF-8
display charset = UTF-8

# workgroup = NT-Domain-Name or Workgroup-Name
workgroup =
WORKGROUP

# server string is the equivalent of the NT Description field
server string = Samba Server

# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the "loopback" interface. For more examples of the syntax see
# the smb.conf man page
; hosts allow = 192.168.1. 192.168.2. 127.
hosts allow = 192.168.0. 127.

   ・
   ・
   ・

#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes

vfs objects = recycle
recycle:repository = .recycle
recycle:keeptree = no
recycle:versions = yes
recycle:touch = no
recycle:maxsize = 0
recycle:exclude = *.tmp ~$*

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /home/netlogon
; guest ok = yes
; writable = no
; share modes = no

   ・
   ・
   ・

[share]
comment = Shared Directory
path = /var/lib/samba/share
public = yes
writable = yes
printable = no
directory mask = 2770
create mask = 0740
force create mode = 0030

vfs objects = recycle
recycle:repository = .recycle
recycle:keeptree = no
recycle:versions = yes
recycle:touch = no
recycle:maxsize = 0
recycle:exclude = *.tmp ~$*

Samba の起動
Samba を起動します。
Samba の自動機を「オン」にしておきます。


[root@aries ~]# chkconfig --level 345 smb on
[root@aries ~]# chkconfig --list smb
smb 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@aries ~]# /etc/rc.d/init.d/smb start
SMB サービスを起動中: [ OK ]
NMB サービスを起動中: [ OK ]

ごみ箱内ファイル自動削除スクリプトの作成
ごみ箱内のファイルを自動で削除するスクリプトを作成します。
ここでは1週間ごとに30日間アクセスの無いごみ箱内のファイルを削除するようにします。


[root@aries ~]# vi /etc/cron.weekly/recyclewatch

/etc/cron.weekly/recyclewatch


#!/bin/bash

for user in `ls /home/`
do
if [ -d /home/$user/.recycle ]
then
tmpwatch -f 720 /home/$user/.recycle
fi
done

if [ -d /var/lib/samba/share/.recycle ]
then
tmpwatch -f 720 /var/lib/samba/share/.recycle
fi

実行権限を付加します。


[root@aries ~]# chmod +x /etc/cron.weekly/recyclewatch

動作確認
Windowsクライアントからエクスプローラーで
\\aries.tatsunet.net\
に接続します。
ユーザー「tatsusmb1」で接続したときに
「share」「tatsusmb1」ディレクトリが公開されていることを確認します。

ユーザー「tatsusmb2」で接続したときに
「share」「tatsusmb2」ディレクトリが公開されていることを確認します。

それぞれのディレクトリにファイルを作成できることを確認します。
また、削除したファイルが「.recycle」ディレクトリに移動することを確認します。
\\aries.tatsunet.net\tatsusmb1\以下でファイルを削除したとき→\\aries.tatsunet.net\tatsusmb1\.recycleディレクトリに移動。
\\aries.tatsunet.net\tatsusmb2\以下でファイルを削除したとき→\\aries.tatsunet.net\tatsusmb2\.recycleディレクトリに移動。
\\aries.tatsunet.net\share\以下でファイルを削除したとき→\\aries.tatsunet.net\share\.recycleディレクトリに移動。

30日間アクセスのないファイルが自動的に削除されることを確認します。

このアーカイブについて

このページには、過去に書かれたブログ記事のうちSambaカテゴリに属しているものが含まれています。

前のカテゴリはDVDです。

次のカテゴリはイベントです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

ウェブページ

Powered by Movable Type 5.01