[精讚] [會員登入]
669

shell scirpt 批次建立samba使用者

建立一csv檔, 兩個欄位如下 5101,532 5102,592 5103,321 第一欄為帳號使用班級加座號, 第二

分享此文連結 //n.sfs.tw/16366

分享連結 shell scirpt 批次建立samba使用者@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
2024-08-26 15:26:41 最後編修
2024-02-22 08:30:32 By igogo
 

 

建立一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

 

END

你可能感興趣的文章

如何檢查網站憑證是否過期 檢查網站憑證

在docker裡跑spring boot+mongo(二) 使用docker-compose 管理多個container 前篇使用docker run 一次建一個container

mongo備份指令 mongodump --host localhost --port 27017 --username root --db

在docker裡跑spring boot+mongo(一) 系統安裝docker ce centos7 + docker ce https://docs.docker.com/in

tmux 將終端機切割成多個視 窗 tmux, multiple terminal

使用expect 讀取外部資料存成陣列 使用expect 讀取外部資料存成陣列

隨機好文

centos 7 移机出現 dracut-initqueue timeout centos 7 移机出現 dracut-initqueue timeout 處理

ArrayList 想移除特定值 想移出water, 使用lambda 的方式如下 List<String> fruits = new Arr

ubuntu ufw ufw 簡易筆記 原則禁止,例外開放 ufw default deny 啟動ufw sudo ufw enable 關掉

Google sheet 建立成績單的總分及排名並提供名字下拉查詢 Google sheet, sum, rank, pull down list

google sheet 限制使用者以點選的方式填答 google sheet 限制使用者以點選的方式填答