How to generate public and private keys for SSH on Mac OS X 10.7 and then share that public key no so password is prompted for a secure connection with a remote computer. OSX 10.9 Mavericks SSH Connection guide is here.
First thing that you need to do is to create a directory that will store your SSH keys and then generate a public and private key for your account, launch the Terminal and type:
<–Puts you in your home directory–>
username@[~]: cd
<– Creates .ssh directory and moves you into it–>
username@[~]: mkdir .ssh ; cd .ssh
<–Creates your private and public key, the blank quotes gives the private key no password, so allowing for automatic logins–>
username@[~]: ssh-keygen -b 1024 -t rsa -f id_rsa -P ""
<–Change into and view the contents of your .ssh directory–>
username@[~]: cd .ssh ; ls -la
-r–r–r– 1 username staff 1.4K Jun 1 11:35 authorized_keys2 <–List of authorized keys–>
-rw——- 1 username staff 887B Jun 1 11:35 id_rsa <–Your private key–>
-rw-r–r– 1 username staff 239B Jun 1 11:35 id_rsa.pub <–Your public key–>
Thats your keys created, don’t give out the private one always keep that one only on your local machine.
You can create automatic logins by adding the contents of your public key to a corresponding destinations authorized key file. In OSX 10.7 its called authorize_keys2 on other OS’es it may be called something similar but will still be in the .ssh directory.
To see and copy your public key:
<–Displays your public SSH key, which you can copy and add to another remote computer –>
username@[~/.ssh]: cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA2CtcmYRmQJX04pZnrTPrU68BZMk9YlbI6CUcFUp RVw29p V7mxW16wd/q9z7n+xytqdp4wsAc/7+24ZVikMhhRetEGr3LSBz5gm9980oTPEy61+pDP2y jafShe5xcszIUnQ rN1ohCuF7Y/a/TG6G6gaJGcLexUiwfTRtCAbpuzfU= [email protected]
On the remote computer if needed change the permssions on the authorized_keys file to write to add new new public key, on a new line paste in your public key, and change it back to read only after for security:
-rw——- 1 username staff 1.4K Jun 1 11:35 authorized_keys
Paste the entire id_rsa.pub content with vi or nano into the authorized_keys file.
If the remote host does not have an “authorized_keys” file simply create one and after the public key is pasted in don’t forget to takeaway write permissions.
So now when you connect via SSH no password is prompted as the remote computer has your public key which is in turn only decrypted by your private key held in your local .ssh/ directory. If you want the communications to be bilateral then repeat the process in the opposite order between the two.
Now the two computers can securely connect with no password prompting, making it ideal to script between the two for file copies or back ups.