Command Line User Management: Creating Accounts via SSH in Mac OS X 10.5 Leopard


3 views

When working with Mac OS X 10.5 (Leopard), the primary tool for user account management from the command line is dscl (Directory Service Command Line Utility). This utility interacts with the Open Directory system, which is macOS's directory services framework.

Here's the fundamental command structure for creating a new user:

sudo dscl . -create /Users/username
sudo dscl . -create /Users/username UserShell /bin/bash
sudo dscl . -create /Users/username RealName "User Full Name"
sudo dscl . -create /Users/username UniqueID 501
sudo dscl . -create /Users/username PrimaryGroupID 20
sudo dscl . -create /Users/username NFSHomeDirectory /Users/username

Let's create a fully functional user account with password and admin privileges:

# Create the user record
sudo dscl . -create /Users/testuser
sudo dscl . -create /Users/testuser UserShell /bin/bash
sudo dscl . -create /Users/testuser RealName "Test User"
sudo dscl . -create /Users/testuser UniqueID 503
sudo dscl . -create /Users/testuser PrimaryGroupID 20
sudo dscl . -create /Users/testuser NFSHomeDirectory /Users/testuser

# Create home directory
sudo mkdir /Users/testuser
sudo chown testuser /Users/testuser

# Set password (will prompt for input)
sudo dscl . -passwd /Users/testuser

# Add to admin group
sudo dscl . -append /Groups/admin GroupMembership testuser

For scripting purposes where you can't interactively enter a password:

# Generate encrypted password (requires PHP installed)
encrypted_pw=$(php -r 'echo crypt("mypassword", "salt");')

# Apply the password
sudo dscl . -passwd /Users/testuser "$encrypted_pw"

After creation, verify the account exists and has correct properties:

dscl . -read /Users/testuser

When working remotely via SSH, the process is identical, but you might want to:

ssh admin@remotehost "sudo dscl . -create /Users/remoteuser && sudo dscl . -passwd /Users/remoteuser"
  • Always use unique UniqueIDs (check existing users with dscl . -list /Users UniqueID)
  • PrimaryGroupID 20 is for standard users (staff group)
  • For admin users, add them to the admin group (GroupID 80)
  • Consider setting password policies with pwpolicy

If you encounter issues:

# Check if user exists
dscl . -list /Users | grep username

# Verify directory permissions
ls -ld /Users/username

# Check system logs
tail -f /var/log/system.log

Before creating user accounts through SSH, ensure you have:

  • Administrator privileges (sudo access)
  • SSH properly configured on the target machine
  • Basic familiarity with Terminal commands

The fundamental command for user creation in OS X 10.5 is:

sudo dscl . -create /Users/username

Here's a full sequence to create a standard user account:

sudo dscl . -create /Users/newuser
sudo dscl . -create /Users/newuser UserShell /bin/bash
sudo dscl . -create /Users/newuser RealName "John Doe"
sudo dscl . -create /Users/newuser UniqueID 503
sudo dscl . -create /Users/newuser PrimaryGroupID 20
sudo dscl . -create /Users/newuser NFSHomeDirectory /Users/newuser
sudo mkdir /Users/newuser
sudo chown newuser /Users/newuser

To establish the user's password (will prompt for input):

sudo dscl . -passwd /Users/newuser

For automated scripts where you need to set password without prompt:

sudo dscl . -passwd /Users/newuser mysecretpassword

Check the new account exists in Directory Services:

dscl . -read /Users/newuser

Or list all users:

dscl . -list /Users

For administrator privileges:

sudo dscl . -append /Groups/admin GroupMembership newuser

Setting account expiration (using timestamp):

sudo dscl . -create /Users/newuser AccountExpiration "12/31/2025"

For bulk operations, consider a shell script:

#!/bin/bash
USERS=("dev1" "dev2" "qa1")
for user in "${USERS[@]}"; do
  sudo dscl . -create /Users/$user
  sudo dscl . -create /Users/$user UserShell /bin/bash
  # Additional properties...
done