管理者/smbd の設定

(3334d) 更新


公開メモ

samba サーバーの設定 (2015-01-19)

概要

普段使いのノートパソコンは Windows 7 で動いているのですが、 そこで VMware Player を走らせて開発環境として Debian を起動できるようになっています。

で、Debian 側のファイルを Windows 7 から簡単に編集するために Debian に samba を入れて、ファイル共有によって Windows 7 からアクセスしようと考えました。

samba の導入

テスト用も兼ねて smbclient も入れておきます。

LANG:console
$ cat /etc/os-release
 PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
 NAME="Debian GNU/Linux"
 VERSION_ID="8"
 VERSION="8 (jessie)"
 ID=debian
 HOME_URL="http://www.debian.org/"
 SUPPORT_URL="http://www.debian.org/support/"
 BUG_REPORT_URL="https://bugs.debian.org/"
$ uname -a
 Linux takeuchi-debian32 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt2-1 (2014-12-08) i686 GNU/Linux
$ sudo samba --version
 Version 4.1.13-Debian
$ sudo aptitude install samba smbclient
 ...

$ sudo service samba restart

Windows7 から検索できない

開発用途で、ローカルでしか使わないつもりで適当にインストールしたためもあり、 始め Debian システムの hostname が takeuchi-debian32 となっていました。

で、名前が長すぎるとダメみたいでした。

そういえば Windows ではコンピュータ名は15文字以下でないとだめなのでした(汗 Google:windows コンピュータ名 長さ

hostname で名前を変えて、samba を再起動したところ nmblookup で引けるようになりました。

LANG:console
$ nmblookup takeuchi-debian32
 name_query failed to find name takeuchi-debian32
$ sudo hostname takeuchi-deb32
$ sudo service samba restart
$ nmblookup takeuchi-debian32
 192.168.133.128 takeuchi-deb32<00>

Windows 7 からもちゃんと見えます。

ホスト takeuchi-deb32 の名前解決ができません

nmblookup はうまく動くようになった物の、 コマンドラインに表記のエラーがしょっちゅう表示されるようになってしまいました。

これは、/etc/hosts の設定が書き換わっていないためでした。

http://nakamura-hiroshi.com/ubuntu/2009/03/post-7.php

LANG:console
$ sudo jed /etc/hosts
 ...

 127.0.1.1       takeuchi-deb32
 ...

とすることで、エラーが出なくなりました。

中身が空

takeuchi-deb32 という名前のネットワーク名は見える物の、 Windows 7 から //takeuchi-deb32/ にアクセスしても中に何も見えませんでした。

これは、

LANG:console
$ testparm
 ...
 
 [homes]
         comment = Home Directories
         valid users = %S
         create mask = 0700
         directory mask = 0700
         browseable = No
 ...

の browsable = No が効いているためで、見えなくて正常なのでした。

ちなみに、browsable = Yes にすると homes というフォルダーが見えますが、 この段階では、見えたとしてもアクセスできない物のようでした?

  • エクスプローラーからは
    • \\takeuchi-deb32\homes にアクセスできません
    • エラーコード: 0x80070043
    • ネットワーク名が見付かりません
  • smbclient からは
    • tree connect failed: NT_STATUS_BAD_NETWORK_NAME

となります。
→ 下記設定後はちゃんとアクセスできました。

browsable = No の設定では、 ホームディレクトリへは //(servername)/(username) の形でアクセスします。

アクセスが拒否される

Debian 側のユーザー名は osamu なので、

Windows 側から //takeuchi-deb32/osamu へアクセスしてみたところ、 ユーザー名とパスワードを聞かれるところまで行く物の、 正しいパスワードを入力しても「アクセスが拒否されました」となりました。

これは samba 導入前に作成したユーザーに対して samba 用のパスワードファイルに登録されていないためでした。(samba 導入後にユーザーを作成した場合には、ちゃんとパスワードの同期を取ってくれるのだそうです。)

http://www.linuxquestions.org/questions/linux-networking-3/samba-issue-with-share-level-security-and-client-lanman-auth-4175419138/

によれば pdbedit -L で登録ユーザー名を確認できるそうで、ここに何も出ない=ユーザーが正しく登録されていない、ということのようです。pdbedit -a でユーザーを登録したところ、アクセスできるようになりました。

LANG:console
$ smbclient //takeuchi-deb32/osamu
 Enter osamu's password:
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.13-Debian]
 tree connect failed: NT_STATUS_ACCESS_DENIED
$ sudo pdbedit -L
 (何も出力されない!)
$ sudo pdbedit -a -u osamu
 new password:
 retype new password:
$ sudo pdbedit -L
 osamu:1000:Osamu Takeuchi
$ smbclient //takeuchi-deb32/osamu
 Enter osamu's password:
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.13-Debian]
 smb: \>ls
   .                                   D        0  Mon Jan 19 20:31:47 2015
   ..                                  D        0  Fri May  9 08:36:28 2014
           .......

 smb: \>^D
$ 

pdbedit -L で Failed to add entry for user (user name). と言われるのは システム側に (user name) というユーザーがない場合なので、先にシステムに ユーザー登録をします。

書き込み可能にする

もともとファイルの編集を行うための共有ですので、 homes を書き込み可能にしておきます。

LANG:console
$ sudo jed /etc/samba/smb.conf
 [homes]
  ...

  read only = no
  ...

$ sudo service samba restart

エラーメッセージを回避

samba のログファイルに cups 関連のエラーがたくさん出ていることに気付きました。

http://roserogue.blogspot.jp/2008/08/unable-to-connect-to-cups-server.html

にもあるようにプリンターを探しに行ってエラーが出ているようです。

そもそもプリンタの共有自体が必要ないので、Google:samba printer 無効 を参考にプリンタの共有をしないように設定しました。

LANG:console
$ tail /var/log/samba/log.smbd
 [2015/01/19 21:58:42.332236,  0] ../source3/printing/print_cups.c:528(cups_async_callback)
   failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL
 [2015/01/19 22:11:43.043939,  0] ../source3/printing/print_cups.c:151(cups_connect)
   Unable to connect to CUPS server localhost:631 - 不正なファイル記述子です
 [2015/01/19 22:11:43.045585,  0] ../source3/printing/print_cups.c:528(cups_async_callback)
   failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL
 [2015/01/19 22:24:43.538669,  0] ../source3/printing/print_cups.c:151(cups_connect)
   Unable to connect to CUPS server localhost:631 - 不正なファイル記述子です
 [2015/01/19 22:24:43.539015,  0] ../source3/printing/print_cups.c:528(cups_async_callback)
   failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL
$ sudo jed /etc/samba/smb.conf
 [global]
  ...

  printing = bsd
  ...

$ sudo service samba restart

これで Unable to connect to CUPS server localhost:631 のエラーは消えましたが、 まだ以下のエラーが出続けました。

http://misc.mat2uken.net/blog/2013/06/13/no_printcap_file.html

を参考にして、

LANG:console
$ tail /var/log/samba/log.smbd
   smbd version 4.1.13-Debian started.
   Copyright Andrew Tridgell and the Samba Team 1992-2013
 [2015/01/19 22:38:48.167090,  0] ../lib/util/become_daemon.c:136(daemon_ready)
   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsUnable to open printcap file /etc/printcap for read!
 [2015/01/19 22:39:48.233443,  0] ../source3/printing/print_standard.c:69(std_pcap_cache_reload)
   Unable to open printcap file /etc/printcap for read!
 [2015/01/19 22:52:48.896825,  0] ../source3/printing/print_standard.c:69(std_pcap_cache_reload)
   Unable to open printcap file /etc/printcap for read!
 [2015/01/19 23:05:49.529105,  0] ../source3/printing/print_standard.c:69(std_pcap_cache_reload)
   Unable to open printcap file /etc/printcap for read!
$ sudo jed /etc/samba/smb.conf
 [global]
  ...

  load printers = no
  printcap name = /dev/null
  ...

$ sudo service samba restart

これで消えたようです。

ちなみに Debian 側から Windows 7 のファイル共有にアクセスするには

smbclient ならそのままで、

LANG:console
$ smbclient //takeuchi-t430/for_debian
 Enter osamu's password:
 Domain=[TAKEUCHI-T430] OS=[Windows 7 Home Premium 7601 Service Pack 1] Server=[Windows 7 Home Premium 6.1]
 smb: \>

のようにアクセスできます。フォルダにマウントするには、cifs-utils を入れて、

LANG:console
$ sudo aptitude install cifs-utils
$ sudo mount.cifs -o username=osamu,rw,sec=ntlm,uid=osamu,gid=osamu,\
                     file_mode=0777,dir_mode=0777 //takeuchi-t430/for_ebian ~/t430/

などとすれば良いようでした。

コメント・質問





Counter: 23789 (from 2010/06/03), today: 1, yesterday: 0