建立一csv檔, 兩個欄位如下
5101,532
5102,592
5103,321
第一欄為帳號使用班級加座號, 第二欄為密碼
建立學生群組
groupadd students
mkdir -p /home/students/111/5/
#!/bin/bash class="5"; csv="${class}.csv"; while IFS="," read -r seatno passwd do user="$seatno"; home="/home/students/111/$class/$user"; #if [ ${#user} > 3 ] #then echo "user: $user" echo "passwd: $passwd" echo "home: $home" useradd $user -g students -m -d $home -s /sbin/nologin; echo -e "$passwd\n$passwd" | passwd $user echo -e "$passwd\n$passwd" | smbpasswd -s -a $user echo "$user created"; #fi done < <(tail -n +1 $csv)
基上smb.conf 設定
[global] workgroup = WORKGROUP server string = %h server (Samba, Ubuntu) log file = /var/log/samba/log.%m syslog = 0 log level = 2 server role = standalone server hosts allow = 127.0.0.1 192.168.0.0/16 172.16.3.0/24 client min protocol = SMB2 client max protocol = SMB3 security = user passdb backend = tdbsam load printers = no #[netdisk] [students] comment = students net disk #create mask = 0755 path = /home/public/students browseable = yes guest ok = no writable = yes [teachers] comment = teachers directory path = /home/public/teachers browseable = yes guest ok = no writable = yes printable = no [homes] comment = %U home directory writable = yes path = %H