Install samba
1 sudo apt-get install samba
Change samba configuration file
/etc/samba$ sudo vim smb.conf
[global]
; use the name of your Samba server instead of [server name] (sv001)
; and your own workgroup instead of [Domain name] VTC
netbios name = sv001
workgroup = VTC
encrypt passwords = yes
server string =
domain master = yes
local master = yes
preferred master = yes
os level = 65
security = user
domain logons = yes
; logon path tells Samba where to put Windows NT/2000/XP roaming profiles
logon path = \\%L\profiles\%u
logon script = %g\logon.bat
logon drive = H:
; logon home is used to specify home directory and
; Windows 95/98/Me roaming profiles location
; logon home = \\%L\%u\.win_profile\%m
time server = yes
; the below works on Red Hat Linux – other OSs might need a different command
add user script = /usr/sbin/useradd –d /dev/null –g users –s /bin/false –m %u
[netlogon]
path = /usr/local/samba/lib/netlogon
writable = no
browsable = no
[profiles]
; you might wish to use a different directory for your
; Windows NT/2000/XP roaming profiles
path = /home/samba-ntprof
browsable = no
writable = yes
create mask = 0600
directory mask = 0700
[homes]
read only = no
browsable = no
guest ok = no
map archive = yes
[transfer]
path = /home/transfer
browsable = yes
guest ok = no
writable = yes
create mask = 0644
directory mask = 0755
[office-docs]
path = /home/office-docs
browsable = yes
guest ok = no
writable = yes
create mask = 0660
directory mask = 0770
force group = office
Command Checker Samba Configuration:
testparm
Create 3 Groups (students, teachers, office)
sudo groupadd students
sudo groupadd teachers
sudo groupadd office
Creating Directory on the Samba Server
The [netlogon] and [profiles] shares defined in our new smb.conf file reference directories on the Samba Server, and it is necessary to create those directories with the proper permissions:
# mkdir – p /usr/local/samba/lib/netlogon (-p create sub folders Like mkdir /usr/local/treat/tyer/)
# chmod 775 /usr/local/samba/lib/netlogon
# mkdir /home/samba-ntprof
# chmod 777 /home/samba-ntprof
# mkdir /home/transfer
# chmod 755 /home/transfer
# mkdir /home/office-docs
Change the group owner (office-docs)
# chgrp office /home/office-docs
# chmod 770 /home/office-docs
Restart the Samba Daemon
# /etc/init.d/samba restart
Create folders 3 in /usr/local/samba/lib/netlogon: (teachers, students, office)
Create logon file in the each folder above:
# /usr/local/samba/lib/netlogon$ (teachers, students, office)
sudo vim logon.bat
In folder teachers
net time \\sv001 /set /yes
net use /delete T:
net use T: \\sv001\transfer
net use /delete O:
net use O: \\sv001\office-docs
Before Save or Close type command :se ff=dos
In folder office
net time \\sv001 /set /yes
net use /delete T:
net use T: \\sv001\transfer
net use /delete O:
net use O: \\sv001\office-docs
Before Save or Close type command :se ff=dos
In folder students
net time \\sv001 /set /yes
net use /delete T:
net use T: \\sv001\transfer
Before Save or Close type command :se ff=dos
Change Samba root password
sudo smbpasswd -a root
Synchronize time
sudo ntpdate swisstime.ethz.ch
Create script file backuppasswdfiles.sh (/home/vtc)
#!/bin/sh
rm –f passwd
cp /etc/passwd .
rm –f shadow
cp /etc/shadow .
rm –f group
cp /etc/group .
rm –f smbpasswd
cp /etc/samba/smbpasswd .
Create script file createsmbuser.sh in vtc user (/home/vtc)
#!/bin/sh
# (-s /bin/false we don't allow user to logon to server)
useradd –s /bin/false –g $2 –G $3 –m $1
# (R: recursive)
chmod -R 700 /home/$1
# (force: don't show warnings)
# (.??* we remove any file with 3 or more letters)
rm –Rf /home/$1/.??*
# (-a: add smbuser)
smbpasswd –a $1
# (-p: protoname or template)
edquota –p test.user $1
# backup password files automatically
./backuppasswdfiles.sh
# (-s /bin/false we don't allow user to logon to server)
useradd –s /bin/false –g $2 –G $3 –m $1
# (R: recursive)
chmod -R 700 /home/$1
# (force: don't show warnings)
# (.??* we remove any file with 3 or more letters)
rm –Rf /home/$1/.??*
# (-a: add smbuser)
smbpasswd –a $1
# (-p: protoname or template)
edquota –p test.user $1
# backup password files automatically
./backuppasswdfiles.sh
Assign execution rights to script
chmod 700 backuppasswdfiles.sh
chmod 700 createsmbuser.sh
Copy Default User
sudo cp –R Default\ User/ /usr/local/samba/lib/netlogon
Create the new users and then
sudo ./createsmbuser.sh <username> <maingroup> <additional groups>
eg. # sudo ./createsmbuser.sh test.user office users,internet
Samba Users
Assign the Computer for Client to login to the Domain Server
sudo useradd –s /bin/false –d /dev/null –g users [computer name$]
Install Quota
use quota documentation (Install Quota Share Limit Space.doc)
Join Windows Computer to Domain
Create addgroup.sh and delgroup.sh script
1. cd
2. vim addgroup.sh
#!/bin/sh
#!/bin/sh
groupnr=`awk -F: '{if ($1 == groupstr) print $3}' groupstr=$2 < /etc/group`
userlist=`awk -F: '{if ($4 == groupnr) print $1}' groupnr=$groupnr < /etc/passwd`
for user in $userlist
do
adduser $user $1
done
./backuppasswdfiles.sh
3. vim delgroup.sh
#!/bin/sh
groupnr=`awk -F: '{if ($1 == groupstr) print $3}' groupstr=$2 < /etc/group`
userlist=`awk -F: '{if ($4 == groupnr) print $1}' groupnr=$groupnr < /etc/passwd`
for user in $userlist
do
deluser $user $1
done
./backuppasswdfiles.sh
4. chmod +x addgroup.sh delgroup.sh
5. sudo ./addgroup.sh <add this group> <to members in this maingroup>
sudo ./addgroup.sh internet teachers
6. sudo ./delgroup.sh <remove this group> <from members in this maingroup>
sudo ./delgroup.sh internet teachers
NOTE:
id <username> (Show group and membership)
smbstatus (Samba Status)
Delete user and password
sudo userdel –r <username>
sudo vim /etc/samba/smbpasswd to delete user & password
sudo rm –r /home/samba-ntprof/user profile
Install a printer share through logon.bat
RUNDLL32 PRINTUI.DLL,PrintUIEntry /in /q /n\\computername\printername
What to do after hard disk crash and reinstallation of Linux
sudo cp /mnt/backup/files/%date%/tree/vtc/group /etc/group
sudo cp /mnt/backup/files/%date%/tree/vtc/passwd /etc/passwd
sudo cp /mnt/backup/files/%date%/tree/vtc/shadow /etc/shadow
sudo cp /mnt/backup/files/%date%/tree/vtc/smbpasswd /etc/samba/smbpasswd
sudo shutdown –r now
sudo cp –R /mnt/backup/files/%date%/tree /home
No comments:
Post a Comment