Batch add users to samba

Source: Internet
Author: User
Add users in samba in batches-Linux Enterprise Application-Linux server application information. The following is a detailed description. I received a ticket from the file server in linux over the past two days. So what we can do with samba is to import users in batches. Some operations are not very thoughtful and I will try again later, start with several related files.
Installation Method:
./Update. sh remove
./Update. sh install
Set smb
./Update. sh set
User.txt is the user password file, user: password


Update. sh

#! /Bin/bash

If ["$1" = "remove"]; then
Aptitude purge samba-y>/dev/null
Apt-get remove samba *-y>/dev/null
Rm-rf/etc/samba>/dev/null
Elif
["$1" = "install"]; then
Echo "Waiting ..................."
Aptitude install samba-f-y
Aptitude install winbind-f-y
Aptitude install verify CT-y
Addgroup kx
Elif
["$1" = "set"]; then
/Etc/init. d/samba stop
Cp./smb. conf/etc/samba/smb. conf-f
SAVEDIFS = $ IFS
IFS =:
While read xname other
Do
Smbpasswd-x $ xname
Done </etc/passwd

While read name passwd
Do
Deluser $ name
Useradd-g kx-k/dev/null-p $ passwd-m-s/bin/false-d/home/$ name> &/dev/null
Chown $ name. kx/home/$ name
./Expect_smb.sh $ name $ passwd>/dev/null
Echo "Add user ##$ name ## with password ##$ passwd ## over! "
Done <./user.txt
/Etc/init. d/samba restart
Fi


./Expect_smb.sh

#! /Usr/bin/CT-f

# FileName: expect_smb.sh

# Add user to the samba server

#1 --- The name of user

#2 --- The passwd of user


Set username [lindex $ argv 0]
Set password [lindex $ argv 1]

Spawn smbpasswd-a $ username
Reset CT "* password :"
Send "$ password \ n"
Reset CT "* password :"
Send "$ password \ n"
CT eof


Smb. conf
[Global]
Workgroup = mygroup
Server string = % h server
; Wins support = no
; Wins server = w. x. y. z
Dns proxy = no
; Name resolve order = lmhosts host wins bcast
; Interfaces = 127.0.0.0/8 eth0
; Bind interfaces only = true
Log file =/var/log/samba/log. % m
Max log size = 1000
; Syslog only = no
Syslog = 0
Panic action =/usr/share/samba/panic-action % d
Security = user
Encrypt passwords = true
Passdb backend = tdbsam
Obey pam restrictions = yes
Invalid users = root
; Unix password sync = no
Passwd program =/usr/bin/passwd % u
Passwd chat = * Enter \ snew \ sUNIX \ spassword: * % n \ n * Retype \ snew \ sUNIX \ spassword: * % n \ n * password \ supdated \ ssuccessfully *.
; Pam password change = no
Domain logons = no
; Logon path =\\ % N \ profiles \ % U
; Logon path =\\ % N \ % U \ profile
; Logon drive = H:
; Logon home =\\ % N \ % U
; Logon script = logon. cmd
; Add user script =/usr/sbin/adduser -- quiet -- disabled-password -- gecos "" % u
Load printers = no
; Printing = bsd
; Printcap name =/etc/printcap
; Printing = cups
; Printcap name = cups
; Printer admin = @ ntadmin
; Include =/home/samba/etc/smb. conf. % m
# You may want to add the following on a Linux system:
Socket options = TCP_NODELAY SO_RCVBUF = 8192 SO_SNDBUF = 8192
; Domain master = auto
; Idmap uid = 10000-20000
; Idmap gid = 10000-20000
; Template shell =/bin/bash
Winbind enum groups = yes
; Winbind enum users = yes
#==================================== Share Definitions ====================== ==========
[Homes]
Comment = Home Directories
Browseable = no
Writable = yes
Create mask = 0700
Directory mask = 0700
Valid users = % S
[Wind]
Comment = wind
Path =/home/wind
Writable = yes
Create mask = 0770
Directory mask = 0770
[Tools]
Comment = tools
Path =/home/tools
Writeable = yes
Create mask = 0700
Directory mask = 0700

; Write list = root, @ ntadmin
; Postexec =/bin/umount/cdrom


User.txt

Kx1: 0
Kx2: 0
Kx3: 0
Kx4: 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.