To create an account in the Users folder
dscl / -create /Users/addfromcli
Create and set the shell property to bash.
dscl / -create /Users/addfromcli UserShell /bin/bash
Create and set the user’s full name. (Displayed in some of the panels/login screen)
dscl / -create /Users/addfromcli RealName "Added From Cli"
Create and set the user’s ID. (this is the unique id, you need to find out what id your last user create was and add one)
dscl / -create /Users/addfromcli UniqueID 503
Create and set the user’s group ID property. (This can be your default group)
dscl / -create /Users/addfromcli PrimaryGroupID 1000
Create and set the user home directory.
dscl / -create /Users/addfromcli NFSHomeDirectory /Local/Users/addfromcli
Set the password. (dont use password as a password)
dscl / -passwd /Users/addfromcli PASSWORD
Some more details can be found on OS X Daily
mkalias
is a binary available in a set of tools here. It can also be installed via Homebrew with brew install osxutils
.
This is a SH shell script that calls AppleScript to create an alias.
I'm including the shell script here for future reference incase it goes missing from the nets.
#!/bin/sh
# make_alias
# This script takes two command-line arguments:
# 1) The name (relative or full path) of a source file or folder (directory)
# 2) The name (relative or full path) of a destination folder (directory)
# The script makes a Finder-style alias to the source file or folder
# and puts it in the specified destination folder.
#
# Cameron Hayne (macdev@hayne.net), December 2003
# Modified as suggested by Paul Russell (prussell@sonic.net), May 2006
# to allow either file or folder as source
# Mofified to work with ".app" files, January 2007
scriptname=`basename $0`
if [ $# -lt 2 ]; then
echo "Usage: $scriptname srcPath destPath"
exit
fi
srcPath=$1
destPath=$2
if [ ! -e "$srcPath" ]; then
echo "$scriptname: $srcPath: No such file or directory"
exit
fi
# remove possible trailing slash from $srcPath
srcPath=${srcPath%/}
# set $srcType to "file" or "folder" as appropriate
if [ -d "$srcPath" ]; then
if [ "${srcPath##*.}" == "app" ]; then
srcType="file"
else
srcType="folder"
fi
else
srcType="file"
fi
# check if the $destPath directory exists
if [ ! -d "$destPath" ]; then
echo "$scriptname: $destPath: No such directory"
exit
fi
# check if we have permission to create a new file in the $destPath directory
if [ ! -w "$destPath" ]; then
echo "$scriptname: No write permission in the directory $destPath"
exit
fi
case $srcPath in
/*) fullSrcPath=$srcPath ;;
~*) fullSrcPath=$srcPath ;;
*) fullSrcPath=`pwd`/$srcPath ;;
esac
case $destPath in
/*) fullDestPath=$destPath ;;
~*) fullDestPath=$destPath ;;
*) fullDestPath=`pwd`/$destPath ;;
esac
/usr/bin/osascript > /dev/null <<EOT
tell application "Finder"
set macSrcPath to POSIX file "$fullSrcPath" as text
set macDestPath to POSIX file "$fullDestPath" as text
make new alias file to $srcType macSrcPath at folder macDestPath
end tell
EOT
Best Answer
The information is accessible through
dscl
. To add the alias "visitor" and be able to use this username for guest login, use the following command:sudo dscl . -merge Users/Guest RecordName visitor