Mac OS Xでコマンドラインからユーザ追加
CLIでユーザ追加する
- Macでのユーザ管理はディレクトリサービスによって管理されているので、dsclコマンドによって操作します。
- Web上に記載されているサンプルでは、UIDやGIDは自動的に採番するようになっています。
サンプルスクリプト
-
TARGETUSER
とPASSWORD
を変更してご利用ください。
- root権限で実行してください
#!/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
-
TARGETUSER
とPASSWORD
を変更してご利用ください。 - root権限で実行してください
#!/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
Author And Source
この問題について(Mac OS Xでコマンドラインからユーザ追加), 我々は、より多くの情報をここで見つけました https://qiita.com/matsubo/items/50a2530e6d6f9ac0645e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .