2017年05月31日

Ubuntu サーバの設定 Windowsファイルサーバー

家庭内で、WindowsPC とLinuxPC でファイルを共有するためのファイルサーバーを構築します。
ネットワーク経由で、WindowsPCからLinuxPC上のファイルを読み書きできるようにするには、「Samba」(サンバ)と呼ばれるサーバーソフトを利用します。

環境:Ubuntu 16.04

Windowsファイルサーバー「Samba」を導入


インストール。

sudo apt-get install samba





共有ディレクトリの設定


共有ディレクトリ(任意の場所)として、
ユーザー認証を必要とせず、フルアクセス可能なディレクトリを作ります。

(例として、"/var/share" を指定した。)

sudo mkdir /var/share
sudo chown nobody:nogroup /var/share
sudo chmod 777 /var/share





samba設定ファイルの変更


設定ファイルを開く。

sudo vi /etc/samba/smb.conf



smb.conf では、
「セクション」と呼ばれる単位ごとに、「パラメータ」を設定します。

セクションは [ ] で括ったセクション名で始まり、次のセクションが始まるまでが一塊です。
セクション内のパラメータは "名前" = "値" という形式で記述します。
セミコロン(;)、シャープ(#)で始まる行や、空白行は無視。



[global] セクション


~省略~

[global]

## Browsing/Identification ###
unix charset = UTF-8
dos charset = CP932

# Change this to the workgroup/NT-domain name your Samba server will part of
workgroup = WORKGROUP

# server string is the equivalent of the NT Description field
server string = %h server (Samba, Ubuntu)

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
# wins support = no

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z

# This will prevent nmbd to search for NetBIOS names through DNS.
dns proxy = no

netbios name = John



unix charset

追加。UNIX系のOSがクライアントとして接続するときの、クライアント側で用いる文字コード。

dos charset

追加。Windows系のクライアントが接続するときの、クライアント側で用いる文字コード。CP932は、Shift-JISを表す。

display charset

以前にはあった。標準入出力時の文字コードの設定だったが、Samba4 からは廃止になったので記述不要。

workgroup

Windows側のワークグループ名に合わせる
※[システムのプロパティ]→[コンピュータ名]を参照。

netbios name

追加。Windowsネットワーク上でのサーバーの名前。

~省略~

###### Authentication #######

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
server role = standalone server

# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.
passdb backend = tdbsam

obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
unix password sync = yes


# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de$
# sending the correct chat script for the passwd program in Debian Sarge).
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n$

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
pam password change = yes

# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
map to guest = bad user



map to guest

"bad user" デフォルトのまま。この設定は、登録されていないユーザーがアクセスした場合に、ゲストアカウントとして扱う設定になります。




共有ディレクトリを定義するセクション


smb.conf の最後に、新たなセクションを追加します。
セクション名が、Windowsから見えるディレクトリ名となります。

~省略~

# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
; write list = root, @lpadmin

[Test]
comment = Public Space
path = /var/share
read only = no
browseable = yes
guest ok = yes
create mask = 0775
directory mask = 0775



comment

Windows側から見た時に付加されるコメント。詳細表示を選んだときに表示される。

path

共有するディレクトリのパス

read only

読み取り専用属性の指定

browseable

「ネットワークコンピュータ」に表示するかどうか。"no" とすると隠し共有ディレクトリになる。

guest ok

ゲストユーザーのアクセスを許可するかどうか

create mask

ファイル作成時にファイルに設定されるパーミッション

directory mask

ディレクトリ作成時にディレクトリに設定されるパーミッション



共有ディレクトリを定義するセクションを増やしていくことで、
サーバーマシン内にWindows共有ディレクトリを増やすことができる。





Sambaの再起動


設定ファイルを保存したら、Sambaを再起動させる。

sudo service smbd restart



再起動後、Windows側からエクスプローラで、ネットワークコンピュータを見ると、
追加したファイルサーバーが見える。
samba_01.png

サーバーにアクセスすれば、追加した共有ディレクトリにアクセスすることができる。
samba_02.png

詳細表示にすれば、追加したコメントも見える。
samba_03.png



あとは、Windows側でネットワークドライブの割り当てを実行しておけば
以降、便利に使えるようになります。
エクスプローラーの、ナビゲーションウィンドウから [PC]を右クリック。
[ネットワークドライブの割り当て] を選択
samba_04.png

ファイルサーバーのIPアドレスと、共有ディレクトリを指定すれば完了。
samba_05.png







まとめ


ファイルサーバーというと大げさだが、
単にWindowsPCとLinuxPCでファイル共有したいというだけでも同じ作業なので、
Sambaを使って、簡単に設定できるようになるとネットワーク環境がぐんと使いやすくなる。
また、スマホやタブレットからも当然アクセスできるので、共有ストレージとして役立つ環境が構築できます。


家庭内のローカルネットワークで使うという設定で、
セキュリティを考慮せず、簡単にアクセスできる環境構築を行った。
家庭内であってもセキュリティを高めた設定をするほうが良いので、
それは改めて続きを書こうと思います



Ubuntu サーバの設定 Windowsファイルサーバー(セキュリティ強化)
posted by Zorinos at 20:00| Comment(0) | Linux | 更新情報をチェックする
この記事へのコメント
コメントを書く
コチラをクリックしてください
ブログランキング・にほんブログ村へ
×

この広告は90日以上新しい記事の投稿がないブログに表示されております。