183 文字
1 分

Mac OS Xでコマンドラインからユーザ追加

CLIでユーザ追加する#

  • Mac でのユーザ管理はディレクトリサービスによって管理されているので、dscl コマンドによって操作します。
  • Web 上に記載されているサンプルでは、UID や GID は自動的に採番するようになっています。

サンプルスクリプト#

  • TARGETUSERPASSWORD を変更してご利用ください。
  • root 権限で実行してください
Terminal window
##!/bin/zsh
TARGETUSER=newuser
PASSWORD="newpassword"
GID=`dscl . list groups gid|grep \^staff | tail -1 | awk '{print $2}'`
dscl . -create /Users/$TARGETUSER
dscl . -create /Users/$TARGETUSER UserShell /bin/bash
dscl . -create /Users/$TARGETUSER RealName $TARGETUSER
maxid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
newid=$((maxid+1))
dscl . -create /Users/$TARGETUSER UniqueID $newid
dscl . -create /Users/$TARGETUSER PrimaryGroupID $GID
dscl . -create /Users/$TARGETUSER NFSHomeDirectory /Users/$TARGETUSER
cp -a /System/Library/User\ Template/English.lproj /Users/$TARGETUSER
chown -R $TARGETUSER\:staff /Users/$TARGETUSER
chmod 701 /Users/$TARGETUSER
dscl . -passwd /Users/$TARGETUSER $PASSWORD
Mac OS Xでコマンドラインからユーザ追加
https://blog.teraren.com/posts/qiita-20130406-50a2530e6d6f9ac0645e/
作者
Yuki Matsukura
公開日
2013-04-06
ライセンス
CC BY-NC-SA 4.0
この記事が役に立ったら
GitHub Sponsorsで応援できます

コメント