Difference between revisions of "Mac tricks"
(→Reset admin password using single-user mode) |
(→Reset admin password using single-user mode) |
||
| Line 22: | Line 22: | ||
===Reset admin password using single-user mode=== | ===Reset admin password using single-user mode=== | ||
* Access the single-user mode by holding the Command key and S on startup. | * Access the single-user mode by holding the Command key and S on startup. | ||
| − | + | <pre> | |
| − | + | mount –uw / | |
| − | + | launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist | |
| − | + | passwd <username> | |
| + | reboot | ||
| + | </pre> | ||
* Log in with your new admin password. | * Log in with your new admin password. | ||
Revision as of 21:54, 17 September 2018
Contents
- 1 When your Mac won't start
- 2 Set the volume from the command line
- 3 Reset admin password using recovery mode
- 4 Reset admin password using single-user mode
- 5 Print from the command line
- 6 To clean up the right-click context menu
- 7 Enable user's personal web site
- 8 Some Terminal tricks
- 9 List all network hardware ports
- 10 Find out which dhcp server assigned the IP address
- 11 Renew DHCP lease on MacOS
- 12 List known disks
- 13 Create a bootable OSX Mavericks on a USB stick / thumb drive
- 14 Show (or set) Power Management Settings
- 15 Turn Sudden Motion Sensor off
- 16 Show hidden files
- 17 Automatically start Apache Web Server at boot time
When your Mac won't start
Startup in single user mode and fsck Briefly:
- hold down Command-S for single-user mode. (Hold down Command-V for verbose mode)
- /sbin/fsck -fy
- reboot
Set the volume from the command line
osascript -e "set Volume 5"
Reset admin password using recovery mode
Forgot the password? Locked out of your Mac?
- Reboot your Mac while holding down the Command key and R. Keep holding the key combination until the loading bar appears.
- Once in the Recovery Mode, select Terminal from the Utilities menu.
- Type “resetpassword” in the Terminal window and hit enter.
- Select the storage device that contains the operating system.
- Select the admin account.
- Click on the Change Password button.
- Enter a new password as well as a new password hint.
- Save and restart from the main menu.
- Log in with your new admin password.
Reset admin password using single-user mode
- Access the single-user mode by holding the Command key and S on startup.
mount –uw / launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist passwd <username> reboot
- Log in with your new admin password.
Print from the command line
Look at the advanced properties of the printer in System Preferences for the queue name (it will be the same as the printer name with all spaces and dashes replaced by underscores).
lp -d <queuename> <file>
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
Enable user's personal web site
From Mountain Lion onwards Sharing control panel no longer contains "Web sharing" to turn on web servers so command line comes to the rescue...
mkdir ${HOME}/Sites 2>/dev/null
sudo cat <<EOCAT >> /etc/apache2/users/$(whoami).conf
<Directory "/Users/$(whoami)/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
EOCAT
sudo apachectl start
To have the Apache server start at each boot, follow above with this...
sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false
Some Terminal tricks
macs.about.com/od/usingyourmac/tp/terminaltricks.htm
List all network hardware ports
networksetup -listallhardwareports
Hardware Port: Wi-Fi Device: en0 Ethernet Address: 78:4f:43:51:7d:73 Hardware Port: Bluetooth PAN Device: en6 Ethernet Address: 78:4f:43:52:2c:f7 Hardware Port: Thunderbolt 1 Device: en3 Ethernet Address: 26:00:31:08:d4:01 Hardware Port: Thunderbolt 2 Device: en1 Ethernet Address: 26:00:31:08:d4:00 Hardware Port: Thunderbolt 3 Device: en4 Ethernet Address: 26:00:31:08:d4:05 Hardware Port: Thunderbolt 4 Device: en2 Ethernet Address: 26:00:31:08:d4:04 Hardware Port: Thunderbolt Bridge Device: bridge0 Ethernet Address: 26:00:31:08:d4:00 VLAN Configurations ===================
Find out which dhcp server assigned the IP address
DHCP server is the line marked as server_identifier
ipconfig getpacket en0
op = BOOTREPLY
htype = 1
flags = 0
hlen = 6
hops = 0
xid = 0xad759efe
secs = 3
ciaddr = 0.0.0.0
yiaddr = 192.168.1.159
siaddr = 192.168.1.13
giaddr = 0.0.0.0
chaddr = 78:4f:43:51:7d:73
sname =
file =
options:
Options count is 11
dhcp_message_type (uint8): ACK 0x5
server_identifier (ip): 192.168.1.13
lease_time (uint32): 0x15180
renewal_t1_time_value (uint32): 0xa8c0
rebinding_t2_time_value (uint32): 0x12750
subnet_mask (ip): 255.255.255.0
broadcast_address (ip): 192.168.1.255
domain_name_server (ip_mult): {192.168.1.13}
domain_name (string): local
router (ip_mult): {192.168.1.1}
end (none):
Renew DHCP lease on MacOS
sudo ipconfig set <interface> DHCP
List known disks
diskutil list
Create a bootable OSX Mavericks on a USB stick / thumb drive
This way worked for me...
- Download the Installer from the App Store. You end up with a file called "Install OS X Mavericks.app" (5.34Gb) in your Applications folder (and the Install OSX application open)
- Format a USB drive. Use Disk Utility. Partition tab, 1 partition, options... GUID. Call it "Untitled". Here's the bit... Check the mount point at the bottom of the screen! (Does it say /Volumes/Untitled?)
- Don't eject / unmount it.
- Open Terminal. Run the following command...
sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
If the mount point was /Volumes/Untitled then this command will work. If it was anything else, you will get an error. Change the name of the "--volume" attribute to what you saw as the mount point.
It all goes well, be prepared to make a cup of tea and take your time drinking it...
Password: Erasing Disk: 0%... 10%... 20%... 30%...100%... Copying installer files to disk... Copy complete. Making disk bootable... Copying boot files... Copy complete. Done.
or
Show (or set) Power Management Settings
sudo pmset -g
Turn Sudden Motion Sensor off
sudo pmset -a sms 0
defaults write com.apple.Finder AppleShowAllFiles TRUE;\killall Finder;\say Files Revealed
and on Mavericks
defaults write com.apple.finder AppleShowAllFiles -boolean true; killall Finder
Automatically start Apache Web Server at boot time
sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false