AppleSauce
http://search.safaribooksonline.com/
hostname
To reset hostname, via bash, after a server has already been setup:
sudo scutil --set HostName servername.example.com
Similarly to determine hostname:
sudo scutil --get HostName
http://snipplr.com/view/2424/change-os-x-hostname/
Alternative method:http://www.geektimes.com/macintosh/os/x/10_0/core/hostname.html
top
to reproduce the parameters of top on linux:
top -XSt -o cpu
If you want top to default to these switches all the time, add this to your ~/.bash_profile
alias top='top -XSt -o cpu'
Boot Options
Verbose Mode
Press Apple-V keys
Also see: http://www.oreillynet.com/pub/h/348Press N key
Choose Bootdisk
Press "option" key
Will display different partitions and netboot if available.Single User mode
Press Apple-S keys
Boot from CD
Press C key
Eject CD at boot
Press mouse or trackpad key
Target mode
Press T key
Target computer should already be attached to client via firewire or thunderbolt before power on
http://www.fif3.com/howto/archives/001983.html
How to reset a lost password in OS X Tiger
Boot into single user mode
press the Apple-S key at poweron
Mount the boot volume for write access
fsck -yf
mount -uw /
Start system daemons
sh /etc/rc
List users
nidump passwd .
Reset password
passwd <account>
References:
http://www.westwind.com/reference/OS-X/commandline/single-user.html
Mac OS X Tiger for Unix Geeks http://www.oreilly.com/catalog/macxtigerunix/
Note: if the following are done from an admin account (instead of root), please add sudo in front of these commands
Also note: If a user's home directory is encrypted, they won't be able to log in if you change their password this way. (In fact, these instructions were needed because of an inability to log in because the password had been changed via passwd.)
Protecting single user mode
All Apple hardware can be booted into single user mode without password by default.
http://docs.info.apple.com/article.html?artnum=106482
To set a password on ppc hardware (OpenFirmware)
Command Line Guide pp 127
To set a password on intel hardware (EFI)
References:
http://www.westwind.com/reference/OS-X/commandline/single-user.html
Mac OS X Tiger for Unix Geeks http://www.oreilly.com/catalog/macxtigerunix/
http://www.macosxhints.com/article.php?story=20020725085134490 - How to fsck with open firmware passwords enabled.
http://www.macgeekery.com/gspot/2006-02/password-protecting_single-user_mode_in_tiger
Startup Items
"All Unix commands run while OS-X is booting up are run as root and have the potential to significantly alter the behavior of your system. Because this is potentially dangerous, creating one of these startup items is fairly difficult. They have a very structured format, and will not load unless they reside in one of two places: /System/Library/StartupItems (reserved for those provided by Apple) or /Library/StartupItems (where you should put yours)."
http://www.osxfaq.com/Tutorials/LearningCenter/HowTo/Startup/index.ws
Reboot
shutdown -r now
Reference: --manuals.info.apple.com-en-Command_Line_v10.4.pdf
Hardware Serial Number
more /etc/systemserialnumbers/xsvr
Reference: http://www.macosxhints.com/article.php?story=20060710091805963
Serial Number login
first 8 characters of hardware serial number and is case sensitive.
Search computers without ip addresses
To search for all Xserves waiting to be setup via Apple Server Assistant.
/System/Library/ServerSetup/sa_srchr 224.0.0.1Reference: http://www.geocenter.com/news/xserve_imaging.html
Finding computers which don't have a DHCP address assigned to them
ping 169.254.255.255
Apple Software Restore (asr)
from man page
SYNOPSIS
DESCRIPTION
asr efficiently copies disk images onto volumes, either directly or via a multicast network stream. asr can also accurately clone volumes without the use of an intermediate disk image.
In its first form, asr copies source (usually a disk image, potentially on an HTTP server) to target. source can be specified using a path in the filesystem, or an http or https URL. It can also be an asr:// URL to indicate a multicast source. asr can also be invoked with its second form to act as a multicast server. In its third form, asr will restore a multicast disk image to a file instead of disk volume. In its fourth form, asr prepares a disk image to be restored efficiently, adding whole-volume and (optionally) file by file checksum information. help and version provide usage and version information, respectively.
clone a volume
asr -source /Volumes/<vol1> -target /Volumes/<vol2>restore a system image onto a volume
asr -source <compressed_image> -target <target_volume> -erasenote: the target drive will be erased
references:
Manually creating an account
Given <account>, <group> (which is usually same as <account>), <uid>, <gid>, <realname>
dscl . create /users/<account> uid <uid>
dscl . create /users/<account> gid <gid>
dscl . create /users/<account> shell /bin/bash
dscl . create /users/<account> home /Users/<account>
dscl . create /users/<account> realname "<realname>"
dscl . create /users/<account> passwd *
dscl . create /groups/<group> gid <gid>
dscl . create /groups/<group> passwd *
Create default directory
ditto --rsrc /System/Library/User\ Template/English.lproj /Users/<account>
Set correct ownership
chown -R <account>:<group> /Users/<account>
Set password
password <account>
Manually granting an account admin privledges
dscl . merge /groups/admin users <account>
Reference: Mac OS X Tiger for Unix Geeks, p79
Updating Software
softwareupdate -i -a
Setting Server License Number
If you’re using a generic setup file, and the serial number isn’t site licensed, after setup you must specify the server’s serial number by using Server Admin or the command line. In Server Admin, select the server, click Settings, and click General. Alternatively, in the Terminal application, use ssh to connect with the server and type:
/System/Library/ServerSetup/serversetup -setServerSerialNumber <serial_number>
Verify:
/System/Library/ServerSetup/serversetup -verifyServerSerialNumber
Display:
/System/Library/ServerSetup/serversetup -getServerSerialNumber
Reference: Server Getting Started Guide p126
Download by command line
curl -O <url>
Installing packages by command line
Mount image
root# hdiutil attach /Volumes/global/software/MacOSXSrvrUpdCombo10.4.7.dmg/dev/disk2 Apple_partition_scheme/dev/disk2s1 Apple_partition_map/dev/disk2s2 Apple_Driver_ATAPI/dev/disk2s3 Apple_HFS /Volumes/Mac OS X Server 10.4.7 Combined Updateroot# df -hFilesystem Size Used Avail Capacity Mounted on/dev/disk1s3 77G 3.0G 73G 4% /devfs 100K 100K 0B 100% /devfdesc 1.0K 1.0K 0B 100% /dev<volfs> 512K 512K 0B 100% /.vol/dev/disk0s3 77G 59G 18G 77% /Volumes/globalautomount -nsl1770B 0B 0B 100% /Networkautomount -fstab2370B 0B 0B 100% /automount/Serversautomount -static2370B 0B 0B 100% /automount/static/dev/disk2s3 227M 208M 18M 92% /Volumes/Mac OS X Server 10.4.7 Combined Updateroot# ls /Volumes/Mac\ OS\ X\ Server\ 10.4.7\ Combined\ Update/.discCookie MacOSXSrvrUpdCombo10.4.7.mpkgInstall package
root# installer -pkg /Volumes/Mac\ OS\ X\ Server\ 10.4.7\ Combined\ Update/MacOSXSrvrUpdCombo10.4.7.mpkg -target /installer: Package name is Mac OS X Server Update Combinedinstaller: Upgrading volume mounted at /.installer: The upgrade was successful.installer: The install requires restarting now.root# reboot
Reference: http://textsnippets.com/posts/show/322
Backing up Personal Files with rsync
turn on Remote Login on the remote machine
rsync -av -e ssh --delete-excluded --exclude=Library/Caches \
--exclude="Pictures/iPhoto Library" --exclude=.Trash --exclude=Library/Mozilla/Profiles///Cache/ --progress \
<account>@<address>:/Users/<account>/ .
Disable Dashboard
http://www.macworld.com/weblogs/macosxhints/2005/08/disabledashboard/index.php http://www.macosxhints.com/article.php?story=20050723123302403&lsrc=osxh
The dread defaults command
We can use defaults to change preferences, including some that don't have a GUI associated with them. For example, if you want Terminal to use focus-follows-mouse, do:
defaults write com.apple.Terminal FocusFollowsMouse Yes
We can read all keys of a particular application, or one particular key, using <tt>read</tt>:
defaults read com.apple.Terminal
defaults read com.apple.Terminal FocusFollowsMouse
See the man page for more details.
I believe ANSI colors are settable via the TCColorArray pref. It is an array of 11 colors; to change one you have to change the whole key (to the best of my knowledge). Not sure what the first three items are, but I /think/ the fourth is the black color, then red, green, yellow, blue, etc., followed by the bright versions. More digging is necessary...
You shouldn't use defaults on a running application, as that application might override what you're trying to do. So if you're changing Terminal, quit Terminal and use an xterm or iTerm if you're so inclined; if you're changing X11 (for example):
defaults write com.apple.X11 no_quit_alert true
stops the incredibly annoying "Are you sure you want to quit" dialogue from happening), use Terminal or iTerm.
ls colors
From: http://hohle.net/scrap_post.php?post=179
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=ExFxCxDxBxegedabagacad
Other examples:
Apple Raid Administration Tool
To run from linux command line:
/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/bin/java -jar ~/Desktop/RAID\ Admin.app/Contents/Resources/Java/RAID_Admin.jar
Security
http://images.apple.com/server/pdfs/Tiger_Server_Security_Config.pdf
http://images.apple.com/server/pdfs/Tiger_Security_Config.pdf
http://www.westwind.com/reference/OS-X/background-processes.html
Command Line Guide pp 127
Securing Initial System Accounts
Securing the Roo Account
Restricting use of sudo
Securing Single User mode
Setting Password Policy
Firewall: ipfw
Listing Rules
In its simplest form, we can list the rules with:
ipfw list
This will list all of the rules ordered by their rule number. To also list the timestamp of the last moment a packet was matched on a specific rule, the following command will accomplish this:
ipfw -t list
Finally, if we wish to list the packet count for matched rules along with the rules themselves, we can issue the following:
ipfw -a list
OR
ipfw show
Both will display the same information in the same way. The first column is the rule number, followed by the number of outgoing matched packets, followed by the number of incoming matched packets, and finally followed by the rule itself.
Removing rule
ipfw del <rule index number>
Flushing all rules
ipfw -q -f flush
logs
/private/var/log/ipfw.log
nat logs
/var/log/alias.log
configuration files
/private/etc/ipfilter/ipfw.conf
/private/etc/ipfilter/ipfw.conf.apple
command line
Enable firewall
sysctl -w net.inet.ip.fw.enable=1Starting/Stopping firewall
sudo serveradminstartipfilterStarting/Stopping NAT
sudo serveradminstartnat
References:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/firewalls-ipfw.html
Command Line Guide p228-238
DHCP server
server control
sudo serveradminstartdhcpleases
/var/db/dhcpd_leases
References: