チップス

samba で Linux サーバを Windows のファイルサーバにする


samba のインストール

yum -y install samba

smb.conf の設定 CentOS

CentOS 6.0, Samba 3.5.4

User認証なし

# -- Netwrok Related Options

workgroup = WORKGROUP
server string = Hoge Samba %v
netbios name = Hoge
unix charset = UTF-8
dos charset = CP932
hosts allow = 127. 192.168.0. 192.168.1.

# -- Standalone Server Options

security = share
guest account = nobody
guest ok = yes
username map = /etc/samba/smbusers

# -- Printing Options

load printers = no
; cups options = raw
disable spoolss = yes
printing = bsd

[Share]
comment = Share Folder
path = /home/share
browseable = yes
writable = yes
create mask = 0777
directory mode = 0777

User認証あり

# -- Netwrok Related Options

workgroup = WORKGROUP
server string = Hoge Samba %v
netbios name = Hoge
unix charset = UTF-8
dos charset = CP932
hosts allow = 127. 192.168.0. 192.168.1.

# -- Standalone Server Options

username map = /etc/samba/smbusers

# -- Printing Options

load printers = no
; cups options = raw
disable spoolss = yes
printing = bsd

sambaをインストールする
yum install samba

firewallの設定
# system-config-firewall-tui
参照URL http://kajuhome.com/security_trouble.shtml

SELinux off
/etc/sysconfig/selinux
 SELINUX=disabled

# /etc/rc.d.init.d/smb start
# /etc/rc.d/init.d/nmb start

CAPコードでかかれた日本語ファイル名をutf-8で表示する

Windows は CP932 という Shift-JIS を拡張した文字コードを使用、Linuxの文字コードは UTF-8 が使われる事が多くなっています。
ファイル名の文字コードを変換する場合 convmv コマンドを使用します。
CP932 から UTF-8 に変換する

$ convmv -f cp932 -t utf-8 * --notest

カレントディレクトリ以下のファイル名をすべて EUC-JP から UTF-8 に変換する。

$ convmv -r -f euc-jp -t utf-8 *  --notest

古いサーバの samba の設定がCAPコードになっており、サーバ移行の時にUTF-8に変換する事になったので goole で検索したらぴったりのコードがありました。
参照URL:http://linuxexpert.ne.jp/modules/pukiwiki/67.html
保存ファイル名:samba-viewfilename.pl

CAPのファイル名をEUCで表示

#!/usr/bin/perl
require "jcode.pl";

if(!@ARGV){$d=".";}else{$d=$ARGV[0];}
&CodeConv($d);

sub CodeConv{
my ($dir) = @_;
my (@f,$fo,$co,$a);

   opendir(IN,$dir);
      @f=readdir IN;
   close IN;

   foreach (@f){
      if (/^[^\.]/){
         $fo = $_;
         s/\:([0-9a-f][0-9a-f])/sprintf "%c",hex($1)/geo;
         $co = &jcode'getcode(*_);
         if ($co eq "sjis"){
            $a = &jcode'sjis2euc(*_);
#            rename "$dir/$fo","$dir/$_";
#            print "Convert: $dir/$fo -> $dir/$_\n";
            print "$fo -> $_\n";
         }
#         if ( -d "$dir/$_" ){
#            &CodeConv("$dir/$_");
#         }
      }
   }
}

参考にしたURL

Samba 2 日本語版で作成したファイルの Samba 3 への移行方法


   チップス