dscl (directory services client)
dscl is a general-purpose utility for operating on Directory Service directory nodes.
“dscl localhost -whatever /Local/Users”, replacing every instance of a solitary “/” with “localhost” and changing /Users to /Local/users. Hope that helps.
Create & delete user accounts from the command line on Mac OS X
dscl / -create /Users/toddharris Create and set the shell property to bash. dscl / -create /Users/toddharris UserShell /bin/bash Create and set the user’s full name. dscl / -create /Users/toddharris RealName "Dr. Todd Harris" Create and set the user’s ID. dscl / -create /Users/toddharris UniqueID 503 Create and set the user’s group ID property. dscl / -create /Users/toddharris PrimaryGroupID 1000 Create and set the user home directory. dscl / -create /Users/toddharris NFSHomeDirectory /Local/Users/toddharris Set the password. dscl / -passwd /Users/toddharris PASSWORD or passwd toddharris
If you would like Dr. Harris to be able to perform administrative functions: dscl / -append /Groups/admin GroupMembership toddharris
sudo dscl localhost -create /Local/Default/Users/username
Creating & deleting system service agent accounts on Mac OS X
sudo ./makeuser.sh
#!bash (-)
#!/bin/bash
#This script will create a user of your choice using your credentials. The user will not show up in the login window until a restart.
#Function to check the current usernames against the new username.
function checkusername {
local testun=$(dscl . -list /Users | grep $userA)
if [ "$testun" == "$userA" ];
then
echo “The username “$userA” already exists”
exit
else
echo “Username is unique!”
fi
}
#Function to check the current userID’s against the new userID.
function checkuserid {
local testuid=$(dscl . -list /Users UniqueID | grep “$userid” | awk ‘{print $2}’ )
if [ "$testuid" == "$userid" ];
then
echo “The userid “$userid” already exists”
exit
else
echo “UserID is unique!”
fi
}
#Funtion to check that both passwords are the same.
function chkpasswd {
if [ $password != $password2 ]
then
echo “Passwords do not match or are blank. Passwords can’t be blank. Exiting…”
exit 0
else
echo “Passwords Match!”
fi
}
#Step 1, enter new credentials to create user with.
echo “Enter Real Name”
read realname
echo “Enter Username”
read userA
checkusername
echo “Enter Password”
read password
echo “Re-Enter Password”
read password2
chkpasswd
#Check to see if your sure you want to use the entered credentials.
echo “Use these creds?”
echo “Real Name: “$realname
echo “Username: “$userA
echo “Password: “$password
echo “Y or N:”
read creds
if [ $creds = y -o $creds = Y ];
then
echo “Let’s make a user named “$userA” with the password “$password
echo “Are you in Single User Mode? (Default N)”
read sum
#Checks to see if your in single user mode. If you are, it loads the directory services plist.
if [ $sum = y -o $sum = Y ];
then
echo “Loading Directory Services”
launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
else
echo “Skipping launchctl load”
fi
#Asks if you need to see all the userID’s already used.
echo “Making user…”
echo “Do you know what userID is availible? (Default Y)”
read existuserid
if [ $existuserid = n -o $existuserid = N ];
then
#Prints the existing user account records and inserts them to users.out.
dsexport users.out /Local/Default dsRecTypeStandard:Users
#Prints users.out to screen.
tail -n 5 users.out
echo “Find the next userID available.”
#Removes users.out to clean up after printing to screen.
rm users.out
fi
#Asks for the new userID. Checks if userID exists using checkuserid function.
echo “OK, Enter new userID number:”
read userid
checkuserid
#The meat of the script. These are the commands that create the user with your specified credentials.
dscl . -create /Users/”"$userA”"
dscl . -create /Users/”"$userA”" UserShell /bin/bash
dscl . -create /Users/”"$userA”" RealName “$realname”
dscl . -create /Users/”"$userA”" UniqueID $userid
dscl . -create /Users/”"$userA”" PrimaryGroupID 80
dscl . -create /Users/”"$userA”" NFSHomeDirectory /Users/”"$userA”"
dscl . -passwd /Users/”"$userA”" $password
dscl . -append /Groups/admin GroupMembership “”$userA”"
echo “All Done, “$userA” was created!”
sleep 2
exit
else
echo “Please Try Script Again!”
exit 1
fi
== a hidden user = emotely creating a HIDDEN user called “a
Quellen:
http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/
-- DetlevLengsfeld 2010-01-08 09:59:00
MacOSX/user | magic | commandline (last edited 2011-11-12 19:03:24 by DetlevLengsfeld)