Recent Musings

Personal blog of Tristan Blease

Generating a pubkey on Mac OS X

Posted by Tristan Blease on 08/23/10 at 12:19 PM

Read on for a quick tutorial on how to generate an SSH pubkey using Mac OS X. This should work for just about any version of Mac OS X and be useful to create public keys for services like Codebase.

  1. Go into the Utilities folder in your Applications folder and open Terminal.app
  2. When the prompt appears, enter 'ssh-keygen' and hit return. This will start the key generator.
    24-107-186-239:~ tristan$
    24-107-186-239:~ tristan$ ssh-keygen
  3. The first question the key generator will ask is where to save the key to. Just hit return to save the key in it's default location
    Enter file in which to save the key (/Users/tristan/.ssh/id_rsa): 
  4. Next, enter a passphrase to secure your key. It will ask you to confirm your passphrase. You can leave this blank, requiring no passphrase, but it is recommended to secure your key. When you use a passphrase, the system will ask you for that passphrase whenever the key is used for the first time after you've logged into your computer.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
  5. Next, you'll be told where your key was saved and where your public key was saved. Select and copy the public key path. You'll need that in a second. The path should look something like /Users/tristan/.ssh/id_rsa.pub.
    Your identification has been saved in /Users/tristan/.ssh/id_rsa
    Your public key has been saved in 
    /Users/tristan/.ssh/id_rsa.pub
    The key fingerprint is:
    13:cc:de:c8:e7:88:4d:62:3f:57:85:5d:f5:88:33:97 
    tristan@24-107-186-236
    The key's randomart image is:
    +--[ RSA 2048]----+
    |              =oA|
    |              .E+|
    |        . o     o|
    |       . . +   . |
    |      . S   + .  |
    |     .   . G o   |
    |    .     . .    |
    |   x o.. .       |
    |    +Xo .        |
    +-----------------+
    
  6. Next, type 'cat ' into the terminal, paste the path to your public key, and hit return. This will output your public key which you can then use elsewhere (like on Codebase)
    24-107-186-239:~ tristan$
    24-107-186-239:~ tristan$ cat 
    24-107-186-239:~ tristan$ cat /Users/tristan/.ssh/id_rsa.pub
  7. Once you've done this, your public key will be output and look similar to:
    ssh-rsa U2FsdGVkX1+VGwbGhYieyuhW+H0QD85yK3/wPCQfiXHLRtGt00AttZH
    N3SdjKFxjK3LsZlBGsve+aX7urQF23LKDM5esPzS7zFo75qSo6XNwPQYcBbpiRH
    xbXOZ+fPLoKjqYWvDEWs+RNMGs7QkQv+Xt096V/di3j48wZyRSStTGWBkEPRceR
    WBB6tSbKd48QNdbsZK1LVkiepw8dWBQNI8wuIEiWDe/TKlHaWCSOftRwQijC/qz
    GIwzBW0MojOR6j4aJU/rWzijFGw== tristan@24-107-186-239
    

You can copy and paste this public key as needed, and it will always be stored at the path where you generated it at (usually /Users/yourusername/.ssh/). Just make sure you're always and only using your public key (id_rsa.pub) and not the private key that was generated (id_rsa).

Filed under:

Permalink | Comments


blog comments powered by Disqus