This has been documented for Joyent SmartMachines, in particular for allowing users other than root to use SSH public key authentication, but is just as applicable for getting SSH public key authentication to work in general. SmartMachine reference: http://wiki.joyent.com/wiki/display/jpc2/Managing+SSH+Keys#ManagingSSHKeys-MultipleSSHKeys
First create the Unix account on the server, e.g.
[root@im ~]# useradd -g staff -d /home/davek -m davek 128 blocks [root@im ~]# passwd davek New Password: Re-enter new Password: passwd: password successfully changed for davek
On the server, create the authorized_keys file in the user’s ~/.ssh directory.
On the client, generate an SSH public/private key pair in the ~/.ssh directory of the user you wish to connect as:
davek@mymachine:~/.ssh$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/davek/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/davek/.ssh/id_rsa. Your public key has been saved in /home/davek/.ssh/id_rsa.pub. The key fingerprint is: davek@mymachine:~/.ssh$
Copy the SSH public key up to the server:
davek@mymachine:~/.ssh# scp id_rsa.pub root@xxx.xxx.xxx.xxx:/home/davek/.ssh id_rsa.pub 100% |*****************************************************************************************************| 401 00:00 davek@mymachine:~/.ssh#
On the server, copy the public key into the target user’s ~/.ssh/authorized_keys file:
[davek@im /home/davek/.ssh]$ cat id_rsa.pub > authorized_keys
On server, change file modes for ~/.ssh/authorized_keys to 600, and to the ~/.ssh directory to 700.
On the client, change file modes for the ~/.ssh directory to 700, and check that file modes on the private key are set to 600.
Test SSH public key authentication:
davek@mymachine:~/.ssh$ ssh davek@xxx.xxx.xxx.xxx Last login: Mon Dec 10 02:41:18 2012 from xxx.xxx.xxx.xxx __ . . _| |_ | .-. . . .-. :--. |- |_ _| ;| || |(.-' | | | |__| `--' `-' `;-| `-' ' ' `-' / ; SmartMachine base 1.8.1 `-' http://wiki.joyent.com/jpc2/SmartMachine+Base
