25 Terminal Tips Every Mac User Should Know
Posted 12/11/2008 at 11:40am
| by Johnathon Williams

The Unix command line is where many (if not most) of OS X’s security practices were born--and it’s still the place to go to lock down files, resolve system conflicts, and erase your tracks.
10. Compress And Password-protect A File or Folder

Password-protected archives can’t be expanded by the Finder, a limitation that adds another layer of hassle, er, security.
The Finder can make zip archives from files and folders in one click from the File menu or the contextual menu summoned with a Control-click. When security is an issue, the Terminal’s zip command supersedes that with its ability to encrypt archived files and folders. The encryption standard is relatively weak by military or industrial standards, but it should be more than enough to defeat a nosy boss or family member. To create an encrypted archive from a folder in the current directory, execute zip – re name-of-archive name-of-folder, replacing name-of-folder with the name of the folder you’d like to compress and name-of-archive with the name you’ve chosen for the zipped file. To retrieve the contents of an encrypted archive, execute unzip archive-file-name.
11. Fix File Permissions

When permission errors prevent you from accessing files or folders, chmod and chown can sort them out.
In a multiuser system such as OS X, file permissions ensure privacy and security. Now and again, though, they can cause problems, especially when different users are swapping things through a shared folder on the same machine. If the permissions controls in the File Info dialog fail to resolve a problem, chmod and chown are certain to.
Generally, chmod is used to assign role-based permissions for users other than the owner. To ensure that anyone can open and modify a file, execute sudo chmod 777 path-to-file, where path-to-file is replaced with the actual file path, which you can generate automatically by dragging a file from the Finder window into the Terminal window.
This assigns full permissions to anyone who uses that machine, which is bad for security but good for convenience. For more limited permissions, execute sudo chmod 644 path-to-file.
This allows anyone to access and open the file, but only the file’s owner can modify it. To modify permissions on a folder and all of its contents, add the -R option after the command name.
Chown, on the other hand, assigns ownership of a file to particular user. If a file you’ve copied from someone else’s account refuses you access, execute sudo chown your-short-user-name path-to-file.
12. Securely Erase Free Space On Your Dard Drive

Disk Utility’s 35-pass standard provides a high degree of security, but can take days to complete on larger drives.
It may sound strange, but deleted files aren’t actually deleted. Emptying the trash merely marks hard drive space as available, without actually removing the data that occupies it. When new data needs the space, it writes over the old data, but until then, anyone with the right software can still recover the original data--and sometimes even after.
Disk Utility offers a one-line Terminal command to scrub free space of existing data. Execute diskutil secureErase freespace 3 /Volumes/name-of-drive. The utility will write to each drive sector 35 times, using a special algorithm. Thirty-five passes is well above the U.S. Department of Defense’s own standard for erasing data, which requires only seven passes.
Be Careful With Sudo
Note that chmod, chown, and several other commands in this tutorial are running under sudo,
which requires an administrator’s password before executing the
proceeding command, because it executes commands as the administrator,
overriding the system’s usual warnings and precautions. Be extremely cautious with this—if sudo tells the system to erase the entire hard drive, for example, the system will do it, no questions asked.
Next Remotely Control Another Mac