there are official apple ways to make usb keys.
there are two ways to make keys. one way is to install a recovery partition , once you boot that, it will download the copy of os x you got when you bought the computer.
the other way is to write the entire 8 gb os x instller to a usb key, that way you install whatever version you want.
if you do it the recovery way on an empty hard disk, your going to get a 2011 version of mac os.
if you do it the other way, you will get a clean install of the most recent os x you can get your hands on.
recovery way
https://support.apple.com/en-us/HT202294
install the entire os x onto a key way ( better )
https://support.apple.com/en-us/HT201372
before that, the old way was to take the dmg and open it, and find the disk file, and then write that to a usb key, but that is the worst thing you can do, because it will start downloading missing pieces. i did that, and it must of downloaded 4 gigs of stuff . thank god no one does that anymore
recovery way pros : 200 megs, small usb key needed
recovery way cons : 4 to 8 gig download, downloads the version of os x for your machine
entire os x way pros , can keep usb key to install os x on any mac that supports it, faster because its always ready.
cons : 4 to 8 gig download, larger usb key needed.
oh I'm sorry i just thought of a 3rd way. some macs came with internet recovery. even if you replace the hard disk, you could still do a command option R and it would download os x over the internet. i think it first downloaded 300 megabites to write to the hard disk, then it rebooted and then it downloaded the 4 gig installer.
here are a list of macs that support this third option
https://support.apple.com/en-us/HT202313
internet recovery is the same as first option , it will download the version that the mac originally came with