SysAdm

SSL certs

To import in the keychain and force to be considered as “authoritative” a self-signed cert use:

$ sudo certtool i certnew.crt k=/System/Library/Keychains/X509Anchors

or

$ sudo certtool i certnew.cer d k=/System/Library/Keychains/X509Anchors

The former is for certs in PEM format, the second for those in DER format.

$ certtool y k=/System/Library/Keychains/X509Anchors

shows the certs in the system X509Anchors file.

Single User mode & Password recovery (Panther)

Boot pressing Command-S; you'll land in single user mode. From there you can mount RW the root filesystem:

  # /sbin/mount -wu /

You then should start a few basic services (the most important could be Netinfo, that contains the account details):

  # /sbin/SystemStarter

Now you can perform the needed maintenance task; to reset a user's password you can use the usual command:

  # passwd <username>

MacPorts (Darwinports)

Searching

Function Command
Search for a port $ port search <regexp>
Show description of a port $ port info <package>
List available ports $ port list
List installed ports $ port installed
Show the port files $ port contents <package>

(Un)Installing

Function Command
Install port # port -c install <port>
Remove port # port -u uninstall <port> [version]

Upgrading

Function Command
Get the latest Portfiles # port sync
Update darwinports infrastructure # port selfupdate
Show outdated ports $ port outdated
Upgrade a port # port -u upgrade <port>
Upgrade outdated ports # port -u upgrade outdated

Cleaning up

Function Command
Clean intermediate files # port clean <port>
Clean all the mess # port clean –all <port>

Meta portnames

You can replace the name of a port with metanames. The most useful are:

  • all
  • active
  • inactive
  • installed
  • outdated

Remove inactive ports

  port installed | grep -v active | awk '/^  / {print "sudo port -u uninstall", $0}' | sh -x

Graph of dependencies

You can create a graph of the dependencies of the installed ports in graphviz format with:

#!/bin/sh
# Graphviz graph of installed ports dependencies
# Create a svg graph using "dot -Tsvg file.dot"

DOTFILE=$0.dot

echo "GETTING INSTALLED PORTS"
port installed | tail +2 | awk '{print $1}' > $0.lista

echo "digraph hello {" > $DOTFILE

sed 's/^/"/;s/$/"/' < $0.lista >> $DOTFILE

for p in `cat $0.lista` ; do
 echo GETTING DEPENDENCIES FOR $p
 #port dependents $p | awk '/depends on/ {print $4,"->",$1}' >> $DOTFILE
 port dependents $p | awk '/depends on/ {print "\"" $4 "\"" ,"->", "\"" $1 "\""}' >> $DOTFILE
done

rm $0.lista

echo "}" >> $DOTFILE

Networking

Identify the DHCP server

To see which DHCP server lent you the address, use:

ipconfig getoption "" server_identifier

Reload Cisco VPN client extensions

If Cisco VPN client gives errors try to perform:

cd /System/Library/StartupItems/CiscoVPN
sudo ./CiscoVPN restart

Show and clean DNS cache

dscacheutil -cachedump -entries host
dscacheutil -flushcache

Note that formerly the command used was lookupd.

Set hostname

Use scutil(8). See Apple forum for insights. Hint:

sudo scutil --set HostName host.doma.in
sudo scutil --set ComputerName bonjourName

Temporarily enable tftpd

Enabling:

$ sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist

Now tftpd is enabled, using /private/tftpboot as a working dir. It's chrooteed, so you'll read and write to the root tftpd directory. You can see the daemon logs using Console.app.

Disabling:

$ sudo launchctl unload /System/Library/LaunchDaemons/tftp.plist

If you prefer a GUI, use TftpServer (download)

Repair a boot disk

Repair a boot disk with install DVD

  1. Insert the Mac OS X Install DVD
  2. Restart the Mac
  3. Immediately after the bong hold down the C key until the Apple logo appears
  4. When the Installer reaches the Introduction phaze, click on Utilities menu and select Disk Utility
  5. Click the First Aid tab
  6. Highlight the boot hard drive volume or partition
  7. Click Repair Disk.

Repair a boot disk without install DVD

  1. Reboot the Mac
  2. Immediately press and hold Command-S, until text begins to scroll on screen. In a few seconds the Unix command line prompt (%) appears
  3. Issue a fsck –fy
  4. Keep fsck-ing until you don't see anymore the ”***** FILE SYSTEM WAS MODIFIED *****” line
  5. When fsck exits with a ”The volume <name of disk> appears to be OK.” you can issue a reboot.

Boot keys

Key Meaning
command+option+O+F Invoke Open Firmware
command+option+P+R Reset PRAM (press until you hear two beeps)
T Startup in FireWire Target Disk Mode
option Invoke Startup Manager
command+S Invoke single-user mode
command+V Invoke verbose mode
C Boot from CD/DVD
X Boot into OS X (if you previously booted from OS 9 on the same volume)
shift (immediately at startup) Safe boot
shift (after boot screen, until login screen) Override auto-login
shift (after login screen) Safe login
option+escape, then click on a user Present name/password login dialog instead of list of users
N Attempt to netboot
command-+shift+option+delete Boot from an external drive

Change hostname

  • Launch ‘System Preferences’
  • Click the ‘Sharing’ icon
  • Type in what you want your new computer name to be

Disk Images

Index a Disk Image

sudo mdutil -i on /Volumes/name_of_image

Convert a .dmg to .iso

hdiutil convert imagefile.dmg -format UDTO -o imagefile.iso
mv imagefile.iso.cdr imagefile.iso

dd(1) a Linux disk image to an USB stick

sudo diskutil umountDisk /dev/diskX
sudo dd if=my-image.img of=/dev/diskX bs=1024k

Mount a disk image

hdiutil mount MyImage.dmg

Hide user accounts in login window

This works in 10.4.

To hide:

sudo defaults write /Library/Preferences/com.apple.loginwindow \
HiddenUsersList -array-add account1 account2 account3

To unhide

sudo defaults write /Library/Preferences/com.apple.loginwindow \
HiddenUsersList -array-add

See http://www.macworld.com/weblogs/macosxhints/2006/08/hidelogin/index.php for details.

Resource forks

From the commandline, to see if a file has a resource fork you can look at the (fake) /rsrc subdir:

ls filename/rsrc

To look inside it, use:

/Developer/Tools/DeRez filename

Security

Secure erase

You can wipe / shred /secure erase a file using the command line command srm(1). srm uses the 35-pass Gutmann algorithm.

Posix ACLs

To enable Posix ACLs in Mac Os X you must issue:

# fsaclctl -p /mntpoint -e

To set the extended attributes, you use the usual chmod command:

# chmod +a "joe allow read,write"

To see the extended permissions, use the -e parameter in ls:

$ ls -le pippo.dat

The fastest way to delete an extended permission entry is:

  1. Find the number of the relevant entry;
  2. Delete it by number:
  $ ls -le pippo.dat
  -rw-r--r-- + 1 ap  wheel  0 Aug 29 20:48 pippo.dat
   0: user:ap deny delete
   1: user:ap allow read,append
  $ chmod -a# 0 pippo.dat

If you want to go the graphical way, one free GUI, Sandbox, is at http://www.mikey-san.net/sandbox/

User Directory

A lot of information regarding the users (traditionally held in /etc/passwd in standard Unices) in Leopard are stored in a DB .

You can access and edit them via the dscl(1) command. Example:

  $ dscl localhost -list /Local/Default/Users
  $ dscl localhost -read /Local/Default/Users/ap UserShell
  $ dscl localhost -readall /Local/Default/Users UserShell

Managing files and permission

Show extended info

With ls, use those flags:

  
  -@      Display extended attribute keys and sizes.
  -e      Print the Access Control List (ACL) associated with the file, if present.
  -O      Include the file flags in a long (-l) output.

Modify file flags

Modify the file flags (like uchg, hidden … ) with the chflags(1) command. Example:

  $ chflags nouchg file.txt
  $ chflags -R nouchg somedir

Spotlight searches

Eject CD/DVD

drutil eject

strace in Leopard

It's called dtruss, and is based on dtrace

Put the machine to sleep

pmset sleepnow
apple/sysadm.txt · Last modified: 2010/11/13 17:06 by ap
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki