Setting your Computer ‘Names’ – Command Line

 

Now some of you may not be aware that your computer even has 1 name, let alone 3, but here I will explain how to set them.
First, by default, your ‘Computer Name’ is set by the Operating System when you initially set your machine up, and it tends to use your account long name and the model of Mac, such as ‘John Smith’s MacBook Air’. I don’t like this as it gives away more information than I’d like, so you should change this by typing the following into Terminal, replacing the name within the quotes with the name you’d like to use

sudo scutil --set ComputerName "Mac1"

you can also change this by going to System Preferences, then Sharing, then changing the entry in Computer Name

 

Next you can change your Bonjour host name, your Bonjour host name is the name that shows up when you go to Finder and look under the Shared tab in the sidebar, to change this, open Terminal and type the following, again, replace the name in quotes with something of your own

sudo scutil --set LocalHostName "MBA1"

 

Finally, we have the hostname, this is the name which your machine can be reached from via the internet, through SSH normally, commonly this would be the DNS name of your machine. again, this would be changed through Terminal by typing the following

scutil --set HostName "mac1.domain.com"

I would recommend only using lowercase letters for this.
to confirm the changes have been successful, you can type the following into Terminal

scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostName

VNC into another Mac – Command Line

To open a VNC connection to another Mac from the Command Line is very simple, you just need to open Terminal and enter the following

open vnc://username@IPADDRESS

This will then launch the screen sharing app and connect to the machine requested, you will then be presented with a login box, so enter the password for the machine

no need for any extra software, it’s all built in

Briefly Magnify Dock Icons

If you have your Dock set up like mine (small icons with magnification switched off) then you may have come across some situations where you would like the icons magnified briefly, for example, when I ARD into some machines with a larger screen size than the one I’m working on, the display is shrunk to fit on my screen, and as such, the icons may not be as distinguishable as you’d like.

So, to work around this without having to change the Preferences then just hold down SHIFT & CTRL and drag your mouse icon over the Dock, you will notice that the icons are now magnified to an acceptable size

just release SHIFT & CTRL and magnification switches off again

Apple Software Update Server – Client configuration

To switch a Mac client from collecting its updates from Apple to your Software Update Server then you will need to apply the following to the client machines

Open Terminal and paste the following text into it

For 10.7

sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/index-lion-snowleopard-leopard.merged-1.sucatalog

if running from Apple Remote Desktop then you can send the following UNIX command as root user

defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/index-lion-snowleopard-leopard.merged-1.sucatalog

For 10.6

sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/index-leopard-snowleopard.merged-1.sucatalog

or if running from ARD then you can send the following as root user

defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/index-leopard-snowleopard.merged-1.sucatalog

For 10.5

sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/

again if running from ARD then you can send the following as root user

defaults write /Library/Preferences/com.apple.SoftwareUpdate CatalogURL http://YOURSERVERNAMEHERE:8088/

To confirm that this has worked, run Software Update on the client and it should add your servers name to the window during the check for updates.

To remove a machine from a local ASUS and collect updates from Apple again then type the following into the Terminal

sudo defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL

or if running from ARD then do the following as root user

defaults delete /Library/Preferences/com.apple.SoftwareUpdate CatalogURL

Change passwords from the command line

If you believe that your admin password has been compromised then it is always a good idea to change it, the dilemma is, if you have the same password for hundreds of machines, then it will be quite a hassle to go round to them all and change it, so you have 2 options

1. Invest in Apple Remote Desktop (ARD) to manage your machines.
2. SSH into all machines and change them that way.

I have ARD, so I will guide you through using that, the solution is in essence the same for either option, it’s just a hell of a lot quicker with ARD.

First, you need to select all the machines you wish to make the amendment on, then, you need to select the Send Unix Task option, you will want to run this as root, so select that option, then type the following into the command window

dscl . -passwd /Users/USERNAME PASSWORD

change USERNAME for the short name of the account you wish to change the password of, and swap PASSWORD for the new password, if you don’t set a new password then it will blank the password and then you will need to set a new one the next time you log in

One downside to this timesaving tip is that the next time you log in to the machines, you will need to have knowledge of the old password, so you can unlock the login keychain for that account.

When using this via SSH, you will need to sudo, otherwise it will fail.

And it goes without saying that this should NEVER be attempted on an account that has been filevault encrypted!