Child pages
  • How to SSH via Public Key Authentication PKA
Skip to end of metadata
Go to start of metadata

Say-Ho Tan updated February 28, 2013 at 10:09 AM


Generate a Public/Private Key Pair

Open a Terminal window on your host machine and type the following:

ssh-keygen -b 2048 -t rsa

This will generate the public/private rsa key pair. You will be prompted on where to save the key; the default location (/Users/ (username) /.ssh/id_rsa) is fine, so you can just hit " Enter ".
You will be prompted "Enter passphrase (empty for no passphrase)." If your goal is to ssh into machines without having to type in your password, leave this field blank and hit " Enter ".
You will be prompted to enter the same passphrase again. Hit " Enter ".

You will receive the following confirmation:
Your identification has been saved in /Users/(username)/.ssh/id_rsa.

Your public key has been saved in /Users/(username)/.ssh/id_rsa.pub.

Transfer the Public Key to Remote Machines

You now need to copy your public key to the machines that you want to ssh to. You must copy the public key to each remote machine.
First, confirm the remote machine has a ".ssh" folder in your accounts home directory. If it is a Mac managed by us, it already does. If it does not, ssh to the remote machine via standard ssh method. In your home directory:

mkdir ./.ssh

Make sure that directory is accessible only to your account:

chmod 700 ./.ssh

Now copy your public key to the remote machine, from the machine you created the keys on:

scp .ssh/id_rsa.pub (name of remote machine) :.ssh/ (name of host machine) .pub

Now ssh into the remote machine you have copied the file to, and cd to the .ssh directory in your home directory:

cd .ssh

You'll see the host.pub file you just copied over. Add its contents to a file named "authorized_keys":

cat (nameofpubfile) .pub >> authorized_keys

You should now be able to ssh to the remote machine without typing your password in every time. Repeat for every remote machine. 

  • No labels