×

Samba with LDAP + ドメインコントローラ

【認証のLDAP化】

LDAPのインストール
# apt-get install slapd ldap-utils nscd
設定
/etc/ldap/slapd.conf の修正
access to *
       by dn="cn=admin,dc=kazz,dc=homeunix,dc=org" write
       by self write
       by * read
/etc/ldap/ldap.conf の修正
HOST 127.0.0.1
BASE dc=kazz,dc=homeunix,dc=org
migrationtoolsのインストール
apt-get install migrationtools
既存データのLDAPへの移行
# cd /usr/share/migrationtools
migration_common.ph の修正
$DEFAULT_MAIL_DOMAIN = "kazz.homeunix.org";
$DEFAULT_BASE = "dc=kazz,dc=homeunix,dc=org";
/etc/passwd の移行
# ./migrate_passwd /etc/passwd > passwd.ldif
/etc/group の移行
# ./migrate_group /etc/group > group.ldif
base.ldif の作成
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=example,dc=com
objectClass: organizationalUnit
ou: Group
ldifのLDAPへの登録
# ldapadd -x -D "cn=admin,dc=kazz,dc=homeunix,dc=org" -W -f base.ldif
# ldapadd -x -D "cn=admin,dc=kazz,dc=homeunix,dc=org" -W -f passwd.ldif
# ldapadd -x -D "cn=admin,dc=kazz,dc=homeunix,dc=org" -W -f group.ldif
NSS module for LDAPのインストール
# apt-get install libnss-ldap
nsswitch.confの修正
/etc/nsswitch.conf の修正
passwd:         compat ldap
group:          compat ldap
shadow:         compat ldap
PAM module for LDAPのインストール
# apt-get install libpam-ldap
/etc/pam.d/common-account の修正
account sufficient      pam_ldap.so
account required        pam_unix.so
/etc/pam.d/common-auth の修正
auth    sufficient      pam_ldap.so
auth    required        pam_unix.so nullok_secure try_first_pass
/etc/pam.d/common-password の修正
password sufficient     pam_ldap.so
password required       pam_unix.so nullok obsecure min=4 max=8 md5
/etc/pam.d/common-session の修正
session sufficient      pam_ldap.so
session required        pam_unix.so

【SambaとLDAPの連携】

Sambaのインストール
apt-get install samba
/etc/samba/smb.conf の修正
workgroup = ドメイン名
netbios name = サーバー名
smbldap-toolsのインスール
apt-get install smbldap-tools samba-doc
LDAP Server の設定
samba.schema の作成
zcat /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz > /etc/ldap/schema/samba.schema
/etc/ldap/slapd.conf の修正
include /etc/ldap/schema/samba.schema
Samba Server の設定
/etc/samba/smb.conf の修正
obey pam restrictions = no
passdb backend = ldapsam:ldap://127.0.0.1/
ldap admin dn = cn=admin,dc=fukudat,dc=com
ldap suffix = dc=fukudat,dc=com
ldap user suffix = ou=People
ldap group suffix = ou=Group
ldap machine suffix = ou=Computer
ldap passwd sync = yes
LDAP admin のパスワードを設定する
$ /etc/init.d/samba restart
$ smbpasswd -w xxxx

【smbldap-tools の設定】

smbldap.conf smbldap_bind.conf の作成
$ zcat /usr/share/doc/smbldap-tools/examples/smbldap.conf.gz > /etc/smbldap-tools/smbldap.conf
$ cp /usr/share/doc/smbldap-tools/examples/smbldap_bind.conf /etc/smbldap-tools/smbldap_bind.conf
/etc/smbldap-tools/smbldap.conf の修正
SID="S-1-5-21-1234567890-1234567890-1234567890"

sambaDomain="NETWORK" #ドメイン名

# LDAPの構成

suffix="dc=fukudat,dc=com"           # LDAP の suffix
usersdn="ou=People,${suffix}"        # ユーザ
computersdn="ou=Computer,${suffix}"  # コンピュータ
groupsdn="ou=Group,${suffix}"        # グループ

sambaUnixIdPooldn="sambaDomainName=NETWORK,${suffix}" #ドメイン名に合わせる

# SAMBAの構成
userSmbHome="\\サーバー名\homes\%U" #サーバー名はsmb.confのnetbios nameで指定したもの
userProfile="\\サーバー名\profiles\%U"
SID は net getlocalsid コマンドで取得

/etc/smbldap-tools/smbldap_bind.conf の修正
slaveDN="cn=Manager,dc=idealx,dc=org"
slavePw="secret"
masterDN="cn=Manager,dc=idealx,dc=org"
masterPw="secret"
ベースエントリの作成
$ smbldap-populate -a Administrator

smbldap-populateで、-a 管理者ユーザ名 と明示的に管理者ユーザを指定しないと、Sambaの管理者ユーザがrootで作成され、Linuxのrootと重複してあまりヨロシクない。
まあ、重複してるので、LDAPには登録されないから問題は無い。ただ二度手間になるので、ここで指定しておくのが吉

追記:実際はあんまり関係なかった。好きにするがヨロシ。
というかむしろ、これでAdministratorのパスを設定しようものなら、
suコマンドでrootになれなくなって危険。

【補足修正】


ドメインによるログインで、『期限が近いのでパスワードを変更しろ』というメッセージが。
パスワードの有効期限がデフォで設定されるようになっているらしい。
なので、以下のように修正を加えた。

/etc/smbldap-tools/smbldap.conf の修正
SID="S-1-5-21-1234567890-1234567890-1234567890"

sambaDomain="NETWORK" #ドメイン名

# LDAPの構成
suffix="dc=fukudat,dc=com"           # LDAP の suffix
usersdn="ou=People,${suffix}"        # ユーザ
computersdn="ou=Computer,${suffix}"  # コンピュータ
groupsdn="ou=Group,${suffix}"        # グループ

sambaUnixIdPooldn="sambaDomainName=NETWORK,${suffix}" #ドメイン名に合わせる

# Default password validation time (time in days) Comment the next line if
# you don't want password to be enable for defaultMaxPasswordAge days (be
# careful to the sambaPwdMustChange attribute's value)
#defaultMaxPasswordAge="46"   #コメントアウト

# SAMBAの構成
userSmbHome="\\サーバー名\homes\%U" #サーバー名はsmb.confのnetbios nameで指定したもの
userProfile="\\サーバー名\profiles\%U"

コメントアウトしないと、デフォでパスワードの有効期限を設定される。
セキュリティ的にはそれが正しいが、ドメインコントローラの運用方針として、
それは好ましくないので修正。すでにあるアカウントについては、手動で変更。
smbldap-usermod -H [UX] ユーザ名   #フラグの編集
smbldap-usermod -B 0 ユーザ名   #パスワード有効期限の無期限化

【ドメインコントローラー化】

LDAP Server の設定
/etc/ldap/slapd.conf の修正
access to attrs=userPassword,sambaNTPassword,sambaLMPassword
Samba Server の設定
/etc/samba/smb.conf の修正
obey pam restrictions = no
admin users = admin # 何でも良い 後で登録する
passdb backend = ldapsam:ldap://127.0.0.1/
ldap admin dn = cn=admin,dc=fukudat,dc=com
ldap suffix = dc=fukudat,dc=com
ldap user suffix = ou=People
ldap group suffix = ou=Group
ldap machine suffix = ou=Computer
ldap passwd sync = yes

passwd program = /usr/sbin/smbldap-passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *all*authentication*tokens*updated*

add user script = /usr/sbin/smbldap-useradd -m "%u"
ldap delete dn = Yes
delete user script = /usr/sbin/smbldap-userdel "%u"
add machine script = /usr/sbin/smbldap-useradd -w "%u"
add group script = /usr/sbin/smbldap-groupadd -p "%g" 
delete group script = /usr/sbin/smbldap-groupdel "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"

logon path =
logon home =

domain logon = yes
admin users のユーザ作成
smbldap-useradd -a admin
smbldap-passwd admin
NTドメインログオン確認
(1)WindowsクライアントマシンをNTドメインに登録
  • Windowsクライアントマシンで、「マイコンピュータ」右クリック⇒「プロパティ」⇒「コンピュータ名」タブ⇒「変更」ボタン押下⇒「ドメイン」にDOMAIN※を入力してOKボタン押下
※/etc/samba/smb.confのworkgroupパラメータに設定した値を指定する
  • 「ユーザー名」にadmin、「パスワード」にadminのパスワードを入力してOKボタン押下
  • 「DOMAINドメインへようこそ」のメッセージが表示されればOK
  • Windowsクライアントマシンを再起動

(2)NTドメインにログオンするユーザの新規作成
smbldap-useradd -a -m test
smbldap-passwd.pl test
smbldap-usermod.pl -F "" test ← 移動プロファイルの無効化
(3)NTドメインにログオンする
  • NTドメインに登録したWindowsクライアントマシンで、作成したユーザー名とパスワードを入力して、ログオン先にDOMAINを選択してログオンできることを確認

ユーザ管理

【ユーザの追加】

smbldap-useradd -a -m name
smbldap-passwd name
smbldap-usermod -F "" name
smbldap-groupmod -m name 'Domain Admins'   # 管理者権限を持たせる ドメイン認証だけでLinuxには影響しない

【グループの管理】(グループで共有出来る領域を作る)

グループの作成と、ユーザのグループへの追加
smbldap-groupadd group   # groupを作成
smbldap-groupmod -m user1,user2 group   # user1とuser2をgroupに追加
グループの共有領域の作成
mkdir /var/samba/gdir
chmod 775 /var/samba/gdir
chgrp group /var/samba/gdir
/etc/samba/smb.conf にセクションの追加
[gshare]
   path = /var/samba/gdir
   read only = no
   force group = group
   force create mode = 664
   force directory mode = 775
   valid users = @group
user1とuser2が書き込めるSamba領域[\\servername\gshare]を作成することが出来る。

【ユーザ追加スクリプト】

/usr/sbin/mkuser
#!/bin/bash

smbldap-useradd -a -m $1
smbldap-usermod -F "" $1
smbldap-groupmod -m $1 'Domain Admins'
smbldap-passwd $11

【グループ追加スクリプト】

/usr/sbin/mkgroup
#!/bin/bash

while getopts "u:" opt
do
    case $opt in
    u)
      U=${OPTARG};;
    \?)
      exit 1;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -ne 1 ]
then
    echo "argument error"
    exit 1
fi

G=$*
IFS=,
function groupadd {
if [ $# -ne 1 ]; then
   echo "error : argument number"
   exit 1
fi

smbldap-groupadd $1
if [ $? -ne 0 ]; then
   exit 1
fi
echo "groupadd ok"

mkdir /***/"$1"
if [ $? -ne 0 ]; then
   exit 1
fi
echo "mkdir ok"

chmod 0775 /***/"$1"
echo "chmod ok"

chgrp "$1" /***/"$1"
echo "chgrp ok"
while read id ; do
   echo $id >> /***/smb.conf
done << EOF

[$1]
   path = /***/"$1"
   read only = no
   writable = yes
   force group = $1
   create mask = 0664
   directory mask = 0775
   valid users = @$1

EOF

echo "smb.conf edit ok"
}

function useradd {
    for user in ${U}; do
        smbldap-groupmod -m $user ${G}
    done
}
groupadd ${G}
useradd

【Samba領域作成スクリプト】

#!/bin/bash

if [ $# -ne 1 ]; then
   echo "error : argument number"
   exit 1
fi

smbldap-groupadd $1
if [ $? -ne 0 ]; then
   exit 1
fi
echo "groupadd ok"

mkdir /***/"$1"
if [ $? -ne 0 ]; then
   exit 1
fi
echo "mkdir ok"

chmod 0775 /***/"$1"
echo "chmod ok"

chgrp "$1" /***/"$1"
echo "chgrp ok"
while read id ; do
   echo $id >> /***/smb.conf
done << EOF

[$1]
   path = /***/"$1"
   read only = no
   writable = yes
   force group = $1
   create mask = 0664
   directory mask = 0775
   valid users = @$1

EOF

echo "smb.conf edit ok"
exit 0

このページへのコメント

MMKrDv I truly appreciate this post.Really looking forward to read more. Awesome.

0
Posted by stunning seo guys 2014年01月22日(水) 11:44:39 返信

tBftWw I truly appreciate this blog article.Really thank you! Awesome.

0
Posted by check it out 2014年01月21日(火) 05:32:49 返信

xtVvSI Wow, great article.Thanks Again. Keep writing.

0
Posted by stunning seo guys 2013年12月30日(月) 21:18:12 返信

4izNGc Looking forward to reading more. Great blog post.Really thank you! Great.

0
Posted by check this out 2013年12月19日(木) 15:53:08 返信

5yZkkK <a href="http://nitcohxvconi.com/">nitcohxvconi</a>, [url=http://wpvktlxkbliz.com/]wpvktlxkbliz[/url], [link=http://bpxgutmvlqlb.com/]bpxgutmvlqlb[/link], http://schvxgtacnpn.com/

0
Posted by mficzm 2013年11月22日(金) 00:42:28 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

Menu

ここは自由に編集できるエリアです。

管理人/副管理人のみ編集できます

広告募集中