Sambaでファイル共有をする

Linux上でプログラムを作っていると、使い慣れたWindowsなどのエディタでプログラムを作りたくなります。そのためには、LinuxのファイルをWindows側から見えるようにしなければなりません。

Sambaというソフトウェアを使うことで、Windowsのネットワーク共有を通じてLinux上のファイルを閲覧・編集できるようになります。ディストリビューションはUbuntu 10.04 LTS Server x64です。

Sambaのインストール

sambaパッケージがあるので、これをそのまま導入します。

$ sudo aptitude install samba

Sambaの設定

Samba本体の設定をします。

% diff -u /etc/samba/smb.conf.orig /etc/samba/smb.conf      [~:0]
--- /etc/samba/smb.conf.orig    2010-08-04 22:59:08.826355859 +0900
+++ /etc/samba/smb.conf 2010-08-04 23:23:19.786405145 +0900
@@ -31,6 +31,12 @@
 #======================= Global Settings =======================

 [global]
+   unix charset = UTF-8
+   dos charset = CP932
+   display charset = UTF-8
+   create mask = 0644
+   directory mask = 0755
+   kernel oplocks = no

 ## Browsing/Identification ###

@@ -99,7 +105,7 @@
 # in this server for every user accessing the server. See
 # /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
 # in the samba-doc package for details.
-#   security = user
+   security = user

 # You may wish to use password encryption.  See the section on
 # 'encrypt passwords' in the smb.conf(5) manpage before enabling.
@@ -244,13 +250,13 @@
 # Un-comment the following (and tweak the other settings below to suit)
 # to enable the default home directory shares.  This will share each
 # user's home directory as \\server\username
-;[homes]
-;   comment = Home Directories
-;   browseable = no
+[homes]
+   comment = Home Directories
+   browseable = no

 # By default, the home directories are exported read-only. Change the
 # next parameter to 'no' if you want to be able to write to them.
-;   read only = yes
+   read only = no

 # File creation mask is set to 0700 for security reasons. If you want to
 # create files with group=rw permissions, set next parameter to 0775.

書き換えが終わったところで、サービスのリスタートをします。

$ sudo service smbd restart

アカウントの管理

Sambaの設定が完了したら、あとはSambaを経由してLinuxサーバのファイルを閲覧するときの、アカウント管理だけになります。

Sambaではいくつかの方法で認証を行うことができます。

  1. UNIXアカウント
  2. LDAP認証
  3. Active Directory
  4. などなど……

今回はUNIXアカウント認証を使って、Sambaへログインできるようにします。このためには、libpam-smbpassパッケージを導入します。

$ sudo aptitude install libpam-smbpass

このパッケージを導入すると、UNIXアカウントのパスワード変更時に、Sambaアカウントのパスワードも同時に設定されるようになります。そのため、導入が終わったところで、passwdコマンドにてパスワードを変更します。

$ passwd

パスワード変更が完了すると、Sambaにログインできるようになります。

まとめ

Linuxを導入するときは既存環境に飽き飽きして「こんな環境なんて捨ててやる!」と思いがちです。しかし、しばらくすると「やっぱ今まで使っていた環境が使いやすい」ということを感じると思います。

今回は既存環境でLinuxファイルを読み書きできるよう、Sambaを使ってWindowsネットワーク共有の設定をしました。WindowsではなくMacOSを使っていても、LinuxサーバをWindows機と思って設定することで、この記事は役に立つと思います。

もっとも、MacOSの場合はNFSを使った方が簡単ではあります。


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *