8.3 Getting ready for public key authentication
Connect to your SSH server using PuTTY with the SSH protocol. When the connection succeeds you will be prompted for your user name and password to login. Once logged in, you must configure the server to accept your public key for authentication:
-
If your server is using the SSH-1 protocol, you should change into the
.ssh
directory and open the fileauthorized_keys
with your favourite editor. (You may have to create this file if this is the first key you have put in it). Then switch to the PuTTYgen window, select all of the text in the ‘Public key for pasting into authorized_keys file’ box (see section 8.2.10), and copy it to the clipboard (Ctrl+C
). Then, switch back to the PuTTY window and insert the data into the open file, making sure it ends up all on one line. Save the file. -
If your server is OpenSSH and is using the SSH-2 protocol, you should follow the same instructions, except that in earlier versions of OpenSSH 2 the file might be called
authorized_keys2
. (In modern versions the sameauthorized_keys
file is used for both SSH-1 and SSH-2 keys.) -
If your server is
ssh.com
's product and is using SSH-2, you need to save a public key file from PuTTYgen (see section 8.2.9), and copy that into the.ssh2
directory on the server. Then you should go into that.ssh2
directory, and edit (or create) a file calledauthorization
. In this file you should put a line likeKey mykey.pub
, withmykey.pub
replaced by the name of your key file. - For other SSH server software, you should refer to the manual for that server.
You may also need to ensure that your home directory, your .ssh
directory, and any other files involved (such as authorized_keys
, authorized_keys2
or authorization
) are not group-writable or world-writable. You can typically do this by using a command such as
chmod go-w $HOME $HOME/.ssh $HOME/.ssh/authorized_keys
Your server should now be configured to accept authentication using your private key. Now you need to configure PuTTY to attempt authentication using your private key. You can do this in any of three ways:
- Select the private key in PuTTY's configuration. See section 4.22.8 for details.
-
Specify the key file on the command line with the
-i
option. See section 3.8.3.18 for details. - Load the private key into Pageant (see chapter 9). In this case PuTTY will automatically try to use it for authentication if it can.