The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Create Hidden Users Script No Longer Working In Snow Leopard (http://hintsforums.macworld.com/showthread.php?t=104926)

macguitarman 09-02-2009 04:23 PM

Create Hidden Users Script No Longer Working In Snow Leopard
 
Create Hidden Users Script No Longer Working In Snow Leopard

Can anyone look at this script and explain why it no longer works in Snow Leopard. What changed in Snow Leopard.

Found this in Mac OS X Hints a year or so ago, very helpful for OS X Admins, who want to create a OS X Account via the CL (dscl), creates the users, name UID, group, home folder, all that stuff, and then also hides it so users who are may also have Admin rights can not see it in the Sys Prefs GUI and delete it or downgrade to Standard.

Also, It would be cool if this script could:

1) Be a double clickable file, when clicked, opens the terminal and presents the text:
"Type a user name to be created" , once done, presents

"Type in a password"

Once that is done, then runs its script to create that user and password

It would be cooler

thanks in advance

Not sure where I can attach the script, so

----
Code:

#!/bin/sh

if [ -z $1 ] ; then
        echo "usage: `basename $0` [username] [password] ([UID] optional) ([GID] optional)"
        exit 1
fi

USERNAME=$1
PASSWORD=$2
USERID=$3
GROUPID=$4

if [ `uname -r | cut -c1` = 8 ] ; then
        PATH='/NetInfo/root'
elif [ `uname -r | cut -c1` = 9 ] ; then
        PATH='/Local/Default'
else
        exit 1
fi

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
        GROUPID=0
        UNIQUEID=0
fi

checkUser ()
{
        if [[ `/usr/bin/dscl localhost list /Local/Default/Users | /usr/bin/grep "$USERNAME" | /usr/bin/grep -v "$USERNAME." | /usr/bin/grep -v ".$USERNAME"` == "$USERNAME" ]] ; then
                echo "the username '$USERNAME' already exists"
                exit 1
        fi
}

makeUser ()
{
        /bin/echo "creating admin user account…"
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME PrimaryGroupID 0
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UniqueID 444
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UserShell /bin/bash
        /usr/bin/dscl localhost passwd $PATH/Users/$USERNAME $PASSWORD
        /usr/bin/dscl localhost append $PATH/Groups/admin GroupMembership $USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME NFSHomeDirectory /var/home/$USERNAME
        /bin/echo "creating new admin account homedir…"
        /bin/mkdir -p /var/home/$USERNAME
        /usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/$USERNAME/
        /usr/sbin/chown -Rf $USERNAME:admin /var/home/$USERNAME
        /bin/echo "confirming what we just did…"
        /bin/ls /var/home/$USERNAME/
        /usr/bin/id $USERNAME
        /bin/echo "if that looks good, we're all set."
}

deleteUser ()
{
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Users/$USERNAME
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Groups/admin GroupMembership $USERNAME
}

hideUser ()
{
        /usr/bin/sudo /bin/cp -n /Library/Preferences/com.apple.loginwindow.plist /Library/Preferences/com.apple.loginwindow.plist.backup
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array $USERNAME
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
}

checkUser
makeUser
hideUser
#deleteUser


honestpuck 09-02-2009 08:27 PM

Hi,

At first glance it looks OK.

What errors are you getting and what, if anything, appears in the console log? Have you tried running each section separately to see what breaks where?

// Tony

tlarkin 09-08-2009 06:24 PM

Here is a script I use at work, it has only been tested in 10.5 as my SL machine is wiped out at the moment.

http://tlarkin.com/tech/create-hidden-user-105

You can also hide it from the GUI too, but if you need to deploy it the script is where it is at.

marcushedenstrom 09-11-2009 09:12 AM

The script macguitarman posted checks the system version, or the version number of the Darwin kernel actually. That is what "uname -r" does. Leopard has Darwin version 9, and SL has version 10.

You can see how Tiger (darwin version 8) stores user information in '/NetInfo/root', and Leopard stores it in '/Local/Default'. Hence the need to distinguish between OS X releases. As you can se, the catch-all case in the if-then-else statement terminates the script.

Provided nothing changed dramatically between 10.5 and 10.6, just change the "9" on row 15 to "10", and the script should work fine on SL.

EDIT:
Okay, that was almost correct.

Instead of usnig 'uname -r | cut -c1' to extract the first digit of the version string, use 'uname -r | cut -d . -f 1'. This will split the string at every dot, and return to us the first segment. Since SL is Darwin version 10.0.0, picking only one digit (i.e. 1) does not make sense.

I successfully created a completely hidden account on SL 10.6.1 using the following script. Is is (should be) still backwards compatible with 10.5.

Code:

#!/bin/sh

if [ -z $1 ] ; then
        echo "usage: `basename $0` [username] [password] ([UID] optional) ([GID] optional)"
        exit 1
fi

USERNAME=$1
PASSWORD=$2
USERID=$3
GROUPID=$4


if [ `uname -r | cut -d . -f 1` = 8 ] ; then
        PATH='/NetInfo/root'
elif [ `uname -r | cut -d . -f 1` = 9 ] ; then
        PATH='/Local/Default'
elif [ `uname -r | cut -d . -f 1` = 10 ] ; then
        PATH='/Local/Default'
else
        exit 1
fi

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
        GROUPID=0
        UNIQUEID=0
fi

checkUser ()
{
        echo "checking user.."
        if [[ `/usr/bin/dscl localhost list /Local/Default/Users | /usr/bin/grep "$USERNAME" | /usr/bin/grep -v "$USERNAME." | /usr/bin/grep -v ".$USERNAME"` == "$USERNAME" ]] ; then
                echo "the username '$USERNAME' already exists"
                exit 1
        fi
}

makeUser ()
{
        /bin/echo "creating admin user account…"
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME PrimaryGroupID 0
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UniqueID 444
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UserShell /bin/bash
        /usr/bin/dscl localhost passwd $PATH/Users/$USERNAME $PASSWORD
        /usr/bin/dscl localhost append $PATH/Groups/admin GroupMembership $USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME NFSHomeDirectory /var/home/$USERNAME
        /bin/echo "creating new admin account homedir…"
        /bin/mkdir -p /var/home/$USERNAME
        /usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/$USERNAME/
        /usr/sbin/chown -Rf $USERNAME:admin /var/home/$USERNAME
        /bin/echo "confirming what we just did…"
        /bin/ls /var/home/$USERNAME/
        /usr/bin/id $USERNAME
        /bin/echo "if that looks good, we're all set."
}

deleteUser ()
{
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Users/$USERNAME
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Groups/admin GroupMembership $USERNAME
}

hideUser ()
{
        /usr/bin/sudo /bin/cp -n /Library/Preferences/com.apple.loginwindow.plist /Library/Preferences/com.apple.loginwindow.plist.backup
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array $USERNAME
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
}

checkUser
makeUser
hideUser
#deleteUser


tlarkin 09-11-2009 09:44 AM

I have read reports that 10.6 breaks hidden user accounts. I had one user (begrudgingly) upgrade to 10.6 all on her own and it broke several of my hidden accounts I use for management.

I recreated them and they seem to work fine, however, I think there might be a bug in it?

norrsund 11-22-2009 01:39 PM

I am not able to get this script to work. Could someone give me details on how to properly run it?

salmon 03-15-2010 01:37 PM

how to run
 
I just tested the script and it works. So to answer how to run I will need to offer some basics..... If some of my steps are not clear, then a different forum may be necessary or if I am too basic, please excuse me because your post was not clear where the failure happened.

Copy and Save the script in your favorite editor (I like TextWrangler) and I typically use the .sh for my shell scripts.
Remember where you saved it.
Run terminal
drill down to the directory you saved it to
type: sudo ./scriptname.sh <username you want to use> <password you want to use>

(tip you can also drag the file into the terminal window, this will give you the full path and file name, at which point you edit the line with the sudo and variables needed. i.e. sudo ./path/filename <username> <password>)

Hope this helps. I know this post is old, but maybe someone else may benefit.

steagle 03-23-2010 12:35 PM

@ salmon - thanks for the instructions, glad i found this thread. i'm having a problem getting this to work though, forgive me if i'm missing something obvious. i used TextWrangler to save the file, giving it the name "script.sh" and placed it on the desktop. Navigated to desktop in Terminal and ran the command - prompted me for password, then gave me a the following message:
"sudo: ./script.sh: command not found"
Do I need to modify anything in the script itself before executing?

win818 04-01-2010 10:11 AM

I am getting the same message as steagle: "sudo: ./script.sh: command not found"

Please help! :)

tlarkin 04-01-2010 10:30 PM

Quote:

Originally Posted by win818 (Post 578008)
I am getting the same message as steagle: "sudo: ./script.sh: command not found"

Please help! :)

You need to run the script with the full path to the name of the script, so for example if the script was on your desktop...

Code:

sudo sh ~/Desktop/myscript.sh
Replace myscript with the name of your actual script.

salmon 06-02-2010 03:01 PM

more clarification
 
I was not clear and thank you tlarkin for explaining the full path. Sometimes in my head it makes sense, but then I look at it later going what was I thinking or I left a chunk out.

before running the script, try checking to see if you can see the script (to make sure you are in the correct directory).
To do this, at the command prompt type ls -l
(ls -l means list the contents of where I am at in long format)
so I might see something like this

admin-001:desktop salmon$ ls -l
total 6686552
-rwxrwxrwx 1 salmon staff 793 Jun 15 2008 01 scriptname.sh

by doing this I can see that the file scriptname.sh is here where my prompt is. when you run the command:
sudo ./scriptname.sh <username you want to use> <password you want to use>
the "./" means in the current directory, in other words you are saying run this script that is right here. So if the script is not right here, then you will get the error "sudo: ./script.sh: command not found"
You can put the full path in like sudo ~/Desktop/myscript.sh or change directory to your desktop (if that is where you saved the script) by typing
cd ~/Desktop
then
sudo ./scriptname.sh <username you want to use> <password you want to use>
would work because the file is in the current directory.
I hope this makes sense and I did not make it clear as mud

slessard 07-06-2010 02:02 AM

Script bug fixes
 
I haven't gone through the whole script yet, but I did find at least two bugs in the script above. Here is the corrected script:


Code:

#!/bin/sh

if [ -z $1 ] ; then
        echo "usage: `basename $0` [username] [password] ([UID] optional) ([GID] optional)"
        exit 1
fi

USERNAME=$1
PASSWORD=$2
USERID=$3
GROUPID=$4


if [ `uname -r | cut -d . -f 1` = 8 ] ; then
        PATH='/NetInfo/root'
elif [ `uname -r | cut -d . -f 1` = 9 ] ; then
        PATH='/Local/Default'
elif [ `uname -r | cut -d . -f 1` = 10 ] ; then
        PATH='/Local/Default'
else
        exit 1
fi

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
        GROUPID=0
        UNIQUEID=0
fi

checkUser ()
{
        echo "checking user.."
        if [[ `/usr/bin/dscl localhost list /Local/Default/Users | /usr/bin/grep "$USERNAME" | /usr/bin/grep -v "$USERNAME." | /usr/bin/grep -v ".$USERNAME"` == "$USERNAME" ]] ; then
                echo "the username '$USERNAME' already exists"
                exit 1
        fi
}

makeUser ()
{
        /bin/echo "creating admin user account…"
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME PrimaryGroupID $GROUPID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UniqueID $UNIQUEID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UserShell /bin/bash
        /usr/bin/dscl localhost passwd $PATH/Users/$USERNAME $PASSWORD
        /usr/bin/dscl localhost append $PATH/Groups/admin GroupMembership $USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME NFSHomeDirectory /var/home/$USERNAME
        /bin/echo "creating new admin account homedir…"
        /bin/mkdir -p /var/home/$USERNAME
        /usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/$USERNAME/
        /usr/sbin/chown -Rf $USERNAME:admin /var/home/$USERNAME
        /bin/echo "confirming what we just did…"
        /bin/ls /var/home/$USERNAME/
        /usr/bin/id $USERNAME
        /bin/echo "if that looks good, we're all set."
}

deleteUser ()
{
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Users/$USERNAME
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Groups/admin GroupMembership $USERNAME
}

hideUser ()
{
        /usr/bin/sudo /bin/cp -n /Library/Preferences/com.apple.loginwindow.plist /Library/Preferences/com.apple.loginwindow.plist.backup
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array $USERNAME
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
}

checkUser
makeUser
hideUser
#deleteUser

The bugs are that every user was being created with the same PrimaryGroupID and the same UniqueID. Though that is still possible with this corrected script the difference is that this script will actually use the group ID and unique ID passed as command line arguments.

fudog 10-16-2010 03:44 PM

Quote:

Originally Posted by slessard (Post 588781)
I haven't gone through the whole script yet, but I did find at least two bugs in the script above. Here is the corrected script:


Code:

#!/bin/sh

if [ -z $1 ] ; then
        echo "usage: `basename $0` [username] [password] ([UID] optional) ([GID] optional)"
        exit 1
fi

USERNAME=$1
PASSWORD=$2
USERID=$3
GROUPID=$4


if [ `uname -r | cut -d . -f 1` = 8 ] ; then
        PATH='/NetInfo/root'
elif [ `uname -r | cut -d . -f 1` = 9 ] ; then
        PATH='/Local/Default'
elif [ `uname -r | cut -d . -f 1` = 10 ] ; then
        PATH='/Local/Default'
else
        exit 1
fi

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
        GROUPID=0
        UNIQUEID=0
fi

checkUser ()
{
        echo "checking user.."
        if [[ `/usr/bin/dscl localhost list /Local/Default/Users | /usr/bin/grep "$USERNAME" | /usr/bin/grep -v "$USERNAME." | /usr/bin/grep -v ".$USERNAME"` == "$USERNAME" ]] ; then
                echo "the username '$USERNAME' already exists"
                exit 1
        fi
}

makeUser ()
{
        /bin/echo "creating admin user account…"
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME PrimaryGroupID $GROUPID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UniqueID $UNIQUEID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UserShell /bin/bash
        /usr/bin/dscl localhost passwd $PATH/Users/$USERNAME $PASSWORD
        /usr/bin/dscl localhost append $PATH/Groups/admin GroupMembership $USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME NFSHomeDirectory /var/home/$USERNAME
        /bin/echo "creating new admin account homedir…"
        /bin/mkdir -p /var/home/$USERNAME
        /usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/$USERNAME/
        /usr/sbin/chown -Rf $USERNAME:admin /var/home/$USERNAME
        /bin/echo "confirming what we just did…"
        /bin/ls /var/home/$USERNAME/
        /usr/bin/id $USERNAME
        /bin/echo "if that looks good, we're all set."
}

deleteUser ()
{
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Users/$USERNAME
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Groups/admin GroupMembership $USERNAME
}

hideUser ()
{
        /usr/bin/sudo /bin/cp -n /Library/Preferences/com.apple.loginwindow.plist /Library/Preferences/com.apple.loginwindow.plist.backup
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array $USERNAME
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
}

checkUser
makeUser
hideUser
#deleteUser

The bugs are that every user was being created with the same PrimaryGroupID and the same UniqueID. Though that is still possible with this corrected script the difference is that this script will actually use the group ID and unique ID passed as command line arguments.


i'm getting this when running this script

-bash: ./hadmin.sh: /bin/sh^M: bad interpreter: No such file or directory


can anyone one help. I've search for sh^M and its not in the script and when I look at the script I cant see anything obviously wrong, but Im new to these scripts... what is it applescript? or some sort of Unix Script I presume?

fudog 10-17-2010 09:53 AM

ok Im having problems with this first line

#!/bin/sh

I assume for some reason my system dosnt have the correct shell loaded?

renaultssoftware 10-17-2010 01:17 PM

Try:
#!/bin/bash

fudog 10-17-2010 05:30 PM

yes mate - I tried that one and it didnt work, same problem. Although I know I'm using Bash as my interactive shell. So god knows why it cant find it in /bin

tw 10-17-2010 05:46 PM

Quote:

Originally Posted by fudog (Post 598763)
i'm getting this when running this script

-bash: ./hadmin.sh: /bin/sh^M: bad interpreter: No such file or directory

try #! /bin/bash as renault said. ^M is a line ending character (carriage return as opposed to linefeed) that sometimes appears in files when you move them ungracefully from a Windows box to a unix machine. possibly one of the profile or resource files that's getting accessed when the shell tries to start got windozed at some point? you might gander through those a bit in TextWrangler.

tlarkin 10-18-2010 09:06 AM

Also, you are saving this in plain text right?

fudog 10-18-2010 09:12 AM

I copied pasted the code from safari into textmate then saved it as .sh

let me have another look actually I think theyre are options for the c-returns when I save

tlarkin 10-18-2010 09:15 AM

Some text editors by default will save as rich text. This will cause problems. I am not too familiar with textmate. I use TextWrangler personally.

fudog 10-18-2010 09:18 AM

meh - just re-saved it using LF for line endings and UTF8 for encoding with TextMate and got this:

Code:

WuWei:Desktop fudog$ sudo ./hadmin.sh hadmin hadmin
Password:
sudo: ./hadmin.sh: command not found
WuWei:Desktop fudog$

[edit]

same result with #!/bin/bash as well

fudog 10-18-2010 09:28 AM

Quote:

Originally Posted by tlarkin (Post 598855)
Some text editors by default will save as rich text. This will cause problems. I am not too familiar with textmate. I use TextWrangler personally.

Textmate should be fine, its a pro text editor.
http://macromates.com/

I can grab textwrangler and give that a go - but I dont think thats the problem now, unfortunately (I wish it was that simple). But I'll try it anyway just in case

tlarkin 10-18-2010 09:30 AM

Quote:

Originally Posted by fudog (Post 598856)
meh - just re-saved it using LF for line endings and UTF8 for encoding with TextMate and got this:

Code:

WuWei:Desktop fudog$ sudo ./hadmin.sh hadmin hadmin
Password:
sudo: ./hadmin.sh: command not found
WuWei:Desktop fudog$

[edit]

same result with #!/bin/bash as well

Try this instead

Code:

sudo sh ~/Desktop/myscript.sh
where myscript.sh is the actual name of the script.

fudog 10-18-2010 09:47 AM

just tried it with TextWrangler and got the same results. booo

fudog 10-18-2010 09:49 AM

Quote:

Originally Posted by tlarkin (Post 598858)
Try this instead

Code:

sudo sh ~/Desktop/myscript.sh
where myscript.sh is the actual name of the script.


same result mate. "Command not found"

I've done ls -l and I can see it there via the terminal

tlarkin 10-18-2010 09:55 AM

OK, lets get some fundamentals here as this thread is old. I know hidden user scripts work because I use them daily when imaging macs at my work.

Please answer the following:

1) What OS X version are you running?

2) what is the exact script are you running?

3) Does any other script work, or is it just this one that is broken?

Thanks

fudog 10-18-2010 10:04 AM

Os x 10.6.4

the script I'm running is this:
Code:

#!/bin/sh

if [ -z $1 ] ; then
        echo "usage: `basename $0` [username] [password] ([UID] optional) ([GID] optional)"
        exit 1
fi

USERNAME=$1
PASSWORD=$2
USERID=$3
GROUPID=$4


if [ `uname -r | cut -d . -f 1` = 8 ] ; then
        PATH='/NetInfo/root'
elif [ `uname -r | cut -d . -f 1` = 9 ] ; then
        PATH='/Local/Default'
elif [ `uname -r | cut -d . -f 1` = 10 ] ; then
        PATH='/Local/Default'
else
        exit 1
fi

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
        GROUPID=0
        UNIQUEID=0
fi

checkUser ()
{
        echo "checking user.."
        if [[ `/usr/bin/dscl localhost list /Local/Default/Users | /usr/bin/grep "$USERNAME" | /usr/bin/grep -v "$USERNAME." | /usr/bin/grep -v ".$USERNAME"` == "$USERNAME" ]] ; then
                echo "the username '$USERNAME' already exists"
                exit 1
        fi
}

makeUser ()
{
        /bin/echo "creating admin user account…"
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME PrimaryGroupID $GROUPID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UniqueID $UNIQUEID
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME UserShell /bin/bash
        /usr/bin/dscl localhost passwd $PATH/Users/$USERNAME $PASSWORD
        /usr/bin/dscl localhost append $PATH/Groups/admin GroupMembership $USERNAME
        /usr/bin/dscl localhost create $PATH/Users/$USERNAME NFSHomeDirectory /var/home/$USERNAME
        /bin/echo "creating new admin account homedir…"
        /bin/mkdir -p /var/home/$USERNAME
        /usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/$USERNAME/
        /usr/sbin/chown -Rf $USERNAME:admin /var/home/$USERNAME
        /bin/echo "confirming what we just did…"
        /bin/ls /var/home/$USERNAME/
        /usr/bin/id $USERNAME
        /bin/echo "if that looks good, we're all set."
}

deleteUser ()
{
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Users/$USERNAME
        /usr/bin/sudo /usr/bin/dscl localhost delete $PATH/Groups/admin GroupMembership $USERNAME
}

hideUser ()
{
        /usr/bin/sudo /bin/cp -n /Library/Preferences/com.apple.loginwindow.plist /Library/Preferences/com.apple.loginwindow.plist.backup
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array $USERNAME
        /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
}

checkUser
makeUser
hideUser
#deleteUser

(sometimes with this alternative on the first line: #!/bin/bash)

I just tried this (test.sh):
Code:

cd /
ls -al
cd /Users
ls -al
cat ~/test.sh


and received the same problem - so that gives us some info

fudog 10-18-2010 10:06 AM

I think i fixed it with:

chmod +x test.sh

fudog 10-18-2010 10:21 AM

so this is the result I got in terminal

Code:

WuWei:Desktop fudog$ sudo ./hadmin.sh hadmin hadmin
checking user..
creating admin user account…
creating new admin account homedir…
>>> Copying /System/Library/User Template/English.lproj/
copying file ./.CFUserTextEncoding ...
3 bytes for ./.CFUserTextEncoding
copying file ./Desktop/.localized ...
0 bytes for ./Desktop/.localized
copying file ./Documents/.localized ...
0 bytes for ./Documents/.localized
copying file ./Documents/About Stacks.pdf ...
466028 bytes for ./Documents/About Stacks.pdf
copying file ./Downloads/.localized ...
0 bytes for ./Downloads/.localized
copying file ./Downloads/About Downloads.pdf ...
557722 bytes for ./Downloads/About Downloads.pdf
copying file ./Library/.localized ...
0 bytes for ./Library/.localized
copying file ./Library/Compositions/.localized ...
0 bytes for ./Library/Compositions/.localized
copying file ./Library/Favorites/.localized ...
0 bytes for ./Library/Favorites/.localized
copying file ./Library/FontCollections/Fixed Width.collection ...
957 bytes for ./Library/FontCollections/Fixed Width.collection
copying file ./Library/FontCollections/Fun.collection ...
872 bytes for ./Library/FontCollections/Fun.collection
copying file ./Library/FontCollections/Modern.collection ...
815 bytes for ./Library/FontCollections/Modern.collection
copying file ./Library/FontCollections/PDF.collection ...
856 bytes for ./Library/FontCollections/PDF.collection
copying file ./Library/FontCollections/Traditional.collection ...
1055 bytes for ./Library/FontCollections/Traditional.collection
copying file ./Library/FontCollections/Web.collection ...
1164 bytes for ./Library/FontCollections/Web.collection
copying file ./Library/Input Methods/.localized ...
0 bytes for ./Library/Input Methods/.localized
copying file ./Library/Preferences/.GlobalPreferences.plist ...
955 bytes for ./Library/Preferences/.GlobalPreferences.plist
copying file ./Library/Preferences/com.apple.symbolichotkeys.plist ...
42 bytes for ./Library/Preferences/com.apple.symbolichotkeys.plist
copying file ./Movies/.localized ...
0 bytes for ./Movies/.localized
copying file ./Music/.localized ...
0 bytes for ./Music/.localized
copying file ./Pictures/.localized ...
0 bytes for ./Pictures/.localized
copying symlink ./Pictures/iChat Icons ...
linked ./Pictures/iChat Icons
copying file ./Public/.localized ...
0 bytes for ./Public/.localized
copying file ./Public/Drop Box/.localized ...
0 bytes for ./Public/Drop Box/.localized
copying file ./Sites/.localized ...
0 bytes for ./Sites/.localized
copying file ./Sites/images/gradient.jpg ...
29315 bytes for ./Sites/images/gradient.jpg
copying file ./Sites/index.html ...
2642 bytes for ./Sites/index.html
confirming what we just did…
.CFUserTextEncoding        Documents                Library                        Music                        Public
Desktop                        Downloads                Movies                        Pictures                Sites
uid=0(hadmin) gid=0(wheel) groups=0(wheel),102(com.apple.sharepoint.group.2),204(_developer),100(_lpoperator),98(_lpadmin),80(admin),61(localaccounts),29(certusers),20(staff),12(everyone),9(procmod),8(procview),5(operator),4(tty),3(sys),2(kmem),1(daemon),101(com.apple.sharepoint.group.1),401(com.apple.sharepoint.group.3)
if that looks good, we're all set.
sudo: unable to cache uid, already exists
sudo: unable to cache uid, already exists
sudo: unable to cache uid, already exists
sudo: unable to cache uid, already exists
WuWei:Desktop fudog$


I can see a new user in preferences, but it has no name (even though I gave the variable called 'hadmin'). I was hoping to not see a user in there, the point being that its invisible. Also Im trying to find the home directory for this new user. I cant find /Local/Default/ - if that is indeed where its meant to be?

thanks for your help so far mate - learning lots here.

[edit] oh I see its meant to be in /var/

fudog 10-18-2010 10:25 AM

Confirmed, there is a new home directory for my user in /var/home/

fudog 10-18-2010 10:31 AM

thats interesting. Although I can see the new user in preferences. It has no name and is just labeled as an admin. But I cant delete the user.

hmmm that because it is root. hmm thats not right, root is visible in my preferences now. odd

tlarkin 10-18-2010 10:35 AM

well if it is 10.6 you can get rid of a lot of that code since you definitely do not need netinfo.

Here is a make-shift one you can try for testing purposes

Code:

#!/bin/bash

# create local hidden admin account
# hard code account variables

shortname="hadmin"
realname="Hidden Administrator"
uniqid=400
homefolder="/private/var"
defaultshell="/bin/bash"
password="mypassword"

dscl . -create /Users/$shortname
dscl . -create /Users/$shortname UserShell ${defaultshell}
dscl . -create /Users/$shortname RealName "${realname}"
dscl . -create /Users/$shortname UniqueID ${uniqid}
dscl . -create /Users/$shortname PrimaryGroupID 20
dscl . -create /Users/$shortname NFSHomeDirectory ${homefolder}
dscl . -passwd /Users/$shortname "${password}"

# now promote user to admin group

dscl . append /Groups/admin GroupMembership ${shortname}

# now set the loginwindow to hide all UIDs under 500

defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE

exit 0

I just whipped this up but it may or may not work as I do not have time to test it. You should make sure the script is executable and ran by root when running it.

fudog 10-18-2010 10:44 AM

the orginal script had this in it

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
GROUPID=0
UNIQUEID=0


would I be right in thinking that groupid=0 uniqueid=0 is the same as root... so the new user I created is conflicting with root?

fudog 10-18-2010 10:46 AM

I'll have a crack later, in deleting this user i just created and start over ;-) - I need to go have some lunch ;D

thanks for the help

tlarkin 10-18-2010 10:52 AM

Quote:

Originally Posted by fudog (Post 598872)
the orginal script had this in it

if [ -z $GROUPID ] || [ -z $UNIQUEID ] ; then
GROUPID=0
UNIQUEID=0


would I be right in thinking that groupid=0 uniqueid=0 is the same as root... so the new user I created is conflicting with root?

Yes UID and GID 0 is root:wheel you need to create a local admin users that is UID below 500 (so between 400 and 500 to be safe) and needs to be in the staff and admin group.

fudog 10-18-2010 01:40 PM

OK I slightly amended your script

Code:

#!/bin/bash

# create local hidden admin account
# hard code account variables

shortname="hadmin"
realname="Hidden Administrator"
UniqID=400
homefolder="/private/var/home"
defaultshell="/bin/bash"
password="mypassword"

dscl . -create /Users/"$shortname"
dscl . -create /Users/$shortname UserShell ${defaultshell}
dscl . -create /Users/$shortname RealName "${realname}"
dscl . -create /Users/$shortname UniqueID ${UniqID}
dscl . -create /Users/$shortname PrimaryGroupID 20
dscl . -create /Users/$shortname NFSHomeDirectory ${homefolder}
dscl . -passwd /Users/$shortname "${password}"

# now promote user to admin group

dscl . append /Groups/admin GroupMembership ${shortname}

# now set the loginwindow to hide all UIDs under 500

defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE

exit 0

things I changed were:
#!/bin/bash (just a typo)
UID to UniqID (had to change this variable, the script wouldnt run with the UID, it is a read only variable)
homefolder="/private/var/home" (this path, I wanted the home dir to be created in home inside var)

It seem to run ok accept that I think the home dir didnt create. Although I was able to log in with this user there is no home dir visible when logged in. And when I physically look in var/home/ there is nothing in it.

cheers

tlarkin 10-18-2010 01:58 PM

I think that by nature home directories create on the fly at first log in. So the home folder may not exist until you actually log in.

Glad that worked for you. I only had about 3 minutes of free time so I just typed that out as fast as I could. Now back to work...as my lunch break is now over.

fudog 10-18-2010 01:59 PM

ok I fixed it by creating another script:

Code:

/bin/mkdir -p /var/home/hadmin
/usr/bin/ditto -rsrc -V /System/Library/User\ Template/English.lproj/ /var/home/hadmin/
/usr/sbin/chown -Rf $USERNAME:admin /var/home/hadmin
/bin/echo "confirming what we just did…"
/bin/ls /var/home/hadmin/
/usr/bin/id hadmin
/bin/echo "if that looks good, we're all set."

I guess youre going to tell me that I dont really need a home folder now arnt you :D - anyway its done. and Im more confident with terminal. cheers

fudog 10-18-2010 02:00 PM

Quote:

Originally Posted by tlarkin (Post 598890)
I think that by nature home directories create on the fly at first log in. So the home folder may not exist until you actually log in.

Glad that worked for you. I only had about 3 minutes of free time so I just typed that out as fast as I could. Now back to work...as my lunch break is now over.

thanks for your help mate - i owe you a pint or two cheers

tlarkin 10-18-2010 02:10 PM

This is where directory services local differs from server side I guess. Server side it creates on the fly when you first log in. Technically if this is for local administration and remote admin connection you don't need a home folder per se, but yeah I get it.

Copying the contents of the user template to the home folder will in fact create the desktop, documents, etc folders. Which is most likely what the server side does under the hood for you if you change anything in particular.

I will have to modify my create user scripts to add options for home folders.

Thanks,
Tom


All times are GMT -5. The time now is 05:31 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.