
我想在 macOS High Sierra 和 Mojave 中從命令列(或使用 shell 腳本)建立使用者。使用者帳戶應該是使用者範本的副本。為了建立模板,我在資料夾 /System/Library/User Template/ 中進行了更改
如果我手動建立用戶,該模板就可以工作。但是,如果我使用現有的 shell 腳本來建立用戶,則模板首選項將被忽略。
這是用於建立使用者帳戶的程式碼
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Only 3 Arguments allowed"
else
account=$1
password=$2
uid=$3
username=$account
realname=$account
usershell=/bin/bash
uniqueid=$uid
primarygroupid=20
passwd=$password
pic="/Library/User Pictures/Fun/Chalk.tif"
upath="/Users/${username}"
echo "Create User ${upath}? (Y) to go on ..."
read yes
if [ "$yes" == Y ]; then
dscl . create $upath
dscl . create $upath UserShell $usershell
dscl . create $upath RealName "${realname}"
dscl . create $upath UniqueID $uniqueid
dscl . create $upath PrimaryGroupID $primarygroupid
dscl . create $upath NFSHomeDirectory $upath
dscl . passwd $upath $passwd
dscl . create $upath picture "${pic}"
else
echo "Nothing created"
fi
fi
有什麼我可以做的嗎?也許可以替代 dscl 來建立使用者帳戶?眾所周知的 Linux 命令 adduser 在這裡不存在。
派崔克