Enable Remote Access – Command Line

To enable Remote Management from the command line, enter the following into Terminal

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -users ARDADMIN -access -on -restart -agent -privs -all -allowAccessFor -specifiedUsers -computerinfo -set1 -1 "INFO1" -set2 -2 "INFO2" -set3 -3 "INFO3" -set4 -4 "INFO4"
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart --configure -access -on -privs -all -users ARDADMIN

You will need to switch ARDADMIN for the account you wish to give ARD access to.

INFO1, INFO2, INFO3, INFO4 refer to the fields located in System Preferences, Sharing, Remote Management, Computer Settings

 

To enable SSH for one specific user, enter the following into Terminal

sudo systemsetup -setremotelogin on
sudo dseditgroup -o create -a USER -t user -u USER -q com.apple.access_ssh

You will need to change USER for the shortname of the user you wish to grant SSH access to.

Disable Gatekeeper – Command Line

To ‘allow applications downloaded from anywhere’ from the command line, enter the following into Terminal

sudo spctl --master-disable

This changes the option located in System Preferences, Security & Privacy, General

This will allow you to install software from sources other than the Mac App Store

Energy Settings – Command Line

So, to set the energy settings via the command line, do the following

Open Terminal and type

sudo systemsetup -setsleep never

This tells your Mac to never sleep, ideal for a server, or a machine running digital signage

 

To set the display to sleep after 15 minutes type the following into Terminal

sudo systemsetup -setdisplaysleep 15

 

To set the machine to wake up when being accessed remotely, type the following into Terminal

sudo systemsetup -setwakeonnetworkaccess on

 

The following ensures the machine boots up every Saturday at 10pm, this is so I can run some maintenance tasks

sudo pmset repeat wakeorpoweron S 22:00:00

 

This next command disables the ability to sleep the machine by pressing the power button

sudo pmset powerbutton 0

 

And this last one tells the machine that it should automatically restart after a power failure

sudo pmset autorestart 1

Command Line File & Folder Manipulation

 

This time I will run through a few of the useful tasks that can be accomplished via the command line regarding file and folder manipulation

cp

used to copy a file or folder, some examples of usage are below

cp donkey.txt monkey.txt

this will copy a file called donkey.txt and call the copy monkey.txt within the same directory

cp donkey.txt ~/Documents

will copy donkey.txt from the current directory to your Documents folder, it will still be called donkey.txt

cp donkey.txt ~/Documents/monkey.txt

will copy donkey.txt from your current folder to your Documents folder and name it monkey.txt

cp *.jpg ~/Pictures

this will copy all of your jpegs from your current folder to your Pictures folder

cp -R Documents Documents_Backup

this will copy the whole Documents folder to another folder called Documents_Backup, to do this you will need to be in your home folder, so you would type cd ~/ before trying to run this command

ditto

ditto is used to copy a directory, but with the added benefit of preserving a lot of the security information, such as file ownership, see usage examples below

ditto Documents Documents_Backup

this will copy the contents of your Documents folder into a folder called Documents_Backup, if you already have a folder called Documents_Backup then it will merge the contents of Documents with those in Documents_Backup

ditto -rsrcFork Documents Documents_Backup

almost exactly the same as above, but with the added support for Mac specific characteristics  such as resource forks

mv

mv is used for moving files, be careful when using this, as you can overwrite files using this, with no chance of recovering the overwritten files

mv  donkey.txt monkey.txt

the command above will rename the file named donkey.txt in your current directory to monkey.txt

mv donkey.txt ~/Documents

moves the file named donkey.txt from your current folder to your Documents folder

mv donkey.txt ~/Documents/monkey.txt

moves the file named donkey.txt from your current folder to your Documents folder, but this time it renames it monkey.txt, if there is already a monkey.txt in that location then it will be overwritten

mv *.jpg ~/Pictures

moves all your jpegs from your current folder to your Pictures folder

rm

Used to delete files or folders, examples of usage below

rm donkey.txt

deletes the file named donkey.txt

rm donkey.*

deletes all files with the name donkey, regardless of their suffix

rm donkey*.*

deletes all files with donkey in the filename, for example, donkeyride.jpg, donkeykong.mov, donkeysdancing.ppt, etc.

rm *.txt

deletes all the files with the .txt suffix

rm -R data

deletes the folder called data and all of its contents

rmdir

used to remove a directory as shown below

rmdir test

will delete a folder called test providing the folder is empty

rmdir -R test

will delete a folder called test, regardless of whether it has any files or folders within it

mkdir

you would use this to create a directory as shown below

mkdir test

this would create a directory named test in the current folder

chmod

commonly used to change permissions on folders or files, to add, remove or specify access for users & groups, examples of usage are shown below

chmod u+w donkey.txt

allows the user write access to the file donkey.txt

chmod u-r donkey.txt

removes the users read access on the file donkey.txt

chmod ug+x donkey.txt

gives user and group execute rights to donkey.txt

chmod o=rw donkey.txt

gives others read and write access to donkey.txt, but disallows execute access

chown

commonly used to change the owner of a file or folder, must be run as root, as shown below

sudo chown dave donkey.txt

changes the owner of donkey.txt to dave

sudo chown dave data

changes the owner of the data folder to dave

sudo chown -R dave data

gives dave ownership of the folder named data, along with all of the files and folders within it